Automatic mean intensity calculations for fluorescent cell images

25 visualizzazioni (ultimi 30 giorni)
I am trying to build a system that is automatically take a set of fluorescents images as input, segment them, then calculate the mean intensity value of each image and store them in excel file.
My question here is the segmentation method, when I tried with my data, it include some small random fluroscene as well, I want to exclude them, maybe by including size threshold but I am not sure how, because I even have culstered cells as well.
image_files = dir('A_raw/*.jpg'); % replace 'path/to/images' with the actual path to your images
num_images = length(image_files);
% create a cell array to store the results
results = cell(num_images + 1, 4);
results{1,1} = 'Image Number';
results{1,2} = 'Mean Cell Intensity';
results{1,3} = 'Mean Control Intensity';
results{1,4} = 'Total Area';
for i = 1:num_images
img = imread(fullfile(image_files(i).folder, image_files(i).name));
gray_img = rgb2gray(img);
med_img = medfilt2(gray_img); % noise filtration
clahe_img = adapthisteq(med_img); % enhance contrast
mask = imbinarize(clahe_img);
inv_mask = ~mask;
cell_props = regionprops(mask, gray_img, 'MeanIntensity', 'Area');
cell_intensity = cat(1, cell_props.MeanIntensity);
cell_area = cat(1, cell_props.Area);
cc_inv = bwconncomp(inv_mask);
control_props = regionprops(cc_inv, gray_img, 'Area', 'MeanIntensity');
control_area = cat(1, control_props.Area);
control_intensity = cat(1, control_props.MeanIntensity);
total_area = sum(cell_area) + sum(control_area);
%show the original image and the binary image side by side
figure;
subplot(1, 2, 1);
imshow(img);
title(['Original Image - Image ', num2str(i)]);
subplot(1, 2, 2);
imshow(mask);
title(['Binary Image - Image ', num2str(i)]);
% store the results in the cell array
results{i+1,1} = i;
results{i+1,2} = mean(cell_intensity);
results{i+1,3} = mean(control_intensity);
results{i+1,4} = total_area;
end
% write the results to an Excel file
writecell(results, 'T20_MATLAB.xlsx');

Risposte (1)

Abhijeet
Abhijeet il 18 Ago 2023
Hi Joudi,
You can set the size threshold using a code like:
% Set the size threshold for excluding small regions
size_threshold = 100; % Adjust this value as needed
Add a filtering step to exclude small regions based on the threshold, like :
% Filter out small regions based on the size threshold
valid_cells = cell_area >= size_threshold;
cell_intensity = cell_intensity(valid_cells);
cell_area = cell_area(valid_cells);
These modifications will introduce the concept of a size threshold and apply it to filter out small regions from the cell properties (cell_intensity and cell_area) before calculating the mean intensity and total area.
This will help you to exclude small random fluorescence while retaining the larger, more significant regions.
Thanks

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by