Matrix output from for loop showing only last iteration values
1 view (last 30 days)
Show older comments
I'm doing a blob analysis to track droplete ejected in my experimental images. I am tracking the centroids of the blobs analyzed in each frame. In each frame, the number of blobs/bounding boxes are different and keeps on changing. The output I wish to obtain is the [X,Y] centroid of all the blobs in each frame, over all frames. I am using a for loop to run over the frames and hBlob Analysis to get the blob estimates. However, I am only getting the centroid data for the last frame. I am not sure how to output the centroids of all blobs in each frame to a common output variable, especially given that the number of blobs in each frame is not the same. Any help woudl be deeply appreciated. The code currently I am using is attached below.
for k = startImage:endImage
s = [sourcePath,s1,num2str(k),s2];
A = imread(s);
B = imread('Background.jpg');
S = imsubtract(B,A);
AA = imcrop(S,[0,0,1280,80]);
T = im2bw(AA,0.2);
Z = bwareaopen(T,50);
hBlobAnalysis = vision.BlobAnalysis('MinimumBlobArea',0,'MaximumBlobArea',300);
[objArea,objCentroid,bboxOut] = step(hBlobAnalysis,Z);
I = insertShape(AA,'Rectangle',bboxOut,'Linewidth',2);
numObj(k) = numel(objArea);
NUM(k,1) = numObj(k);
if numObj(k) == 0
objCentroid = [0 0];
else
xlswrite('centroid.xlsx',objCentroid);
end
imshow(I);
end
0 Comments
Answers (1)
Image Analyst
on 28 Nov 2020
You need to index it with the frame number, like
[objArea,objCentroid(frameNumber, 1:2),bboxOut] = step(hBlobAnalysis,Z);
1 Comment
Dheeraj Cherukat
on 28 Nov 2020
Hi Image Analyst,
Could you please reply on the question asked on the below link. Your comments and gtuidance would highly appreciated please.
https://www.mathworks.com/matlabcentral/answers/654418-how-can-i-feed-a-thrsholded-image-after-thermal-image-processing-as-an-input-to-a-sun-tracking-syst#comment_1149088
See Also
Categories
Find more on Computer Vision with Simulink 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!