MATLAB: How to find the pixel size of connected components in an image and then compare pixel size of each connected component with the pixel size of connected components of the next frame and choose the approximately similar size connected components

computer visiondigital image processingdigital signal processingimage processingImage Processing Toolbox

So,I am reading a video and then saving its frames and in each frame I am finding the connected components and then labelling them.Now lets say I have the image below.In this the pixel size of green cloud on left will be compared with pixel size of both green and red cloud in the second image.If the pixel size of red cloud in second image matches with the pixel size of green cloud in first image then they should save as a pair.Similar procedure needs to be followed for the red cloud in first frame.I have saved these frames but I don't know how to find the pixel size of these green and red clouds separately and then compare them with the next frame's clouds.How can I do that?

Best Answer

It looks like you've already segmented the image into regions and then have labeled the image with bwconncomp() or bwlabel() already, and then are displaying with a color map or perhaps created an RGB image with
% Let's assign each blob a different color to visually show the user the distinct blobs.
coloredLabels = label2rgb (labeledImage, 'hsv', 'k', 'shuffle'); % pseudo random color labels
So, just put your labeled image into regionprops(), and get the areas
props = regionprops(labeledImage, 'Area');
allAreas = [props.Area];
Now that is just the areas. You don't know what area it corresponds to because as the blobs move around, what was blob #1 in one frame might suddenly become blob #2 or #9 or some other ID number. This is because of how the blobs are found. So you're going to have to do tracking if your blobs move around. You can do this if you also find the centroids and if the blob doesn't move very much from one frame to the next so you can just assign the blob numbers to the closest blob from the prior frame.