How do I store data in a table from a for loop?
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Star Strider
2020-10-3
I do not follow everything you are doing, however if you simply want to save the ‘diameter’ result:
diameter(i) = sqrt((area*4)/pi); % Scalar Result
diameter{i} = sqrt((area*4)/pi); % Non-Scalar Result
Note the curly brackets {} in the second option, denoting a cell array. If you are not familiar with cell arrays, see Access Data in Cell Array and related documentation for more information.
4 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!