How do I store data in a table from a for loop?
3 ビュー (過去 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!