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
Sign in to comment.