How to save information from a for loop
Afficher commentaires plus anciens
%% DEFINE input and output path
full_folder = 'C:\Users\RR\Desktop\practice\input_folder_T_60_inj_05';
output_folder = uigetdir("select folder");
input_files = fullfile(full_folder,"*.tif");
subfolders = dir(input_files);
%% background subtraction
background = im2uint16(mat2gray(imread(subfolders(1).name)));
%% Image processing
for i = 1 : length(subfolders)
image = im2uint16(mat2gray(imread(subfolders(i).name)));
image_back_sub = image - background;
image_gray = im2gray(image_back_sub);
tilt = imrotate(image_gray,-0.7,'bilinear','crop');
%color_inversion = imcomplement(image_gray); % this code works for color inversion
BinaryImage=imbinarize(tilt, 0.1);
bw1 = imopen(BinaryImage, strel('line', round(size(BinaryImage,2)*0.03), 0));
bw2 = imdilate(bw1, strel('square', 4));
bw3 = imdilate(bw2, strel('square', 2));
stats = regionprops(bw3);
data = struct2table(stats)
[~,idx] = max(data.Area(:,1))
r = data(idx,:)
sprayRadius = r.BoundingBox(1,3)
sprayHeight = r.BoundingBox(1,4)
imwrite(bw3,[output_folder '/', subfolders(i).name]);
end

stats is the table shown above. I want to store last two values as sprayRadius and sprayHeight in every iteration. How can I do this? Thanks in advance. Reference images are in the comments (img1,img2,background)
3 commentaires
Image Analyst
le 8 Jan 2022
Why is there a loop? if bw2 does not change, then the regionprops won't change and so no loop is needed.
Rohit Thokala
le 8 Jan 2022
Rohit Thokala
le 9 Jan 2022
Réponse acceptée
Plus de réponses (1)
Image Analyst
le 9 Jan 2022
What is b? It shows b in the error but I don't see it in your code. You might have to attach your entire m-file.
Maybe try
bb = vertcat(stats.BoundingBox);
allWidths = bb(:, 3);
allHeights = bb(:, 4);
sprayRadius(i) = max(allWidths);
sprayHeights(i) = max(allHeights);
Catégories
En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

