How to save information from a for loop
이전 댓글 표시
%% 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
Image Analyst
2022년 1월 8일
Why is there a loop? if bw2 does not change, then the regionprops won't change and so no loop is needed.
Rohit Thokala
2022년 1월 8일
Rohit Thokala
2022년 1월 9일
채택된 답변
추가 답변 (1개)
Image Analyst
2022년 1월 9일
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);
카테고리
도움말 센터 및 File Exchange에서 Language Support에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

