How do I store data in a table from a for loop?
Show older comments
Dear Matlab-Community,
I am working on a code to analyze images. The code so far works really well, but I can not seem to find out how to continue.
How I want the code to work is reading in multiple images and detect the area of the binarized image. Everything works fine but since I am reading in at least 20 images, the goal is to save each data from each loop from the "diameter" calculation.
Can anyone help a desperate student?
This is the code i wrote so far (please don't judge, I just started like 3 weeks ago):
% clc;
source = uigetdir([]);
d = dir(fullfile(source, '*.tif'));
x_axis = 142.7; %Microns
Resolution_x = 1264; %Pixels
micron = x_axis/Resolution_x ; %Microns/Pixel
%%
% Calculating Droplet Size Distribution
for i = 1:length(d)
read_filename = [num2str(i),'.tif'];
rgb = imread(fullfile(source, read_filename));
%Extracting green color map and converting it to gray scale
gmat = rgb(:,:,2);
gray_g = mat2gray(gmat);
%Set max contrast in graymaps
gray_g_enh = imadjust(gray_g,stretchlim(gray_g),[]);
%Binarize grayscale and morphological commands
g_bw = imbinarize(gray_g_enh,'global');
g_morphed = bwmorph(g_bw,'majority',Inf);
g_morphed1 = bwmorph(g_morphed,'fill',Inf);
bw_filled = imfill(g_morphed1,'holes');
stats = regionprops(logical(bw_filled),'area');
stats_array = struct2array(stats);
area = micron*stats_array;
diameter = sqrt((area*4)/pi);
end
Accepted Answer
More Answers (0)
Categories
Find more on Images in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!