how to detect objects in a box in a greyscale image
1 view (last 30 days)
Pravindkumaran Baskaran on 28 Sep 2022
how can i detect objects in a box in a greyscale image.Managed to make the objects standout but how can i detect the number of objects. Attached two images, original image and the binarised image.
Image Analyst on 28 Sep 2022
I'd use imabsdiff to find the difference between an image with no objects there and your image with objects there. Then threshold that difference image, call imfill, and then count blobs with bwlabel. Here's a start
diffImage = imabsdiff(grayImage, backgroundImage);
mask = diffImage > 10; % Or whatever.
mask = imfill(mask, 'holes');
% Get rid of specks less than 50 pixels in area
mask = bwareaopen(mask, 50);
[labeledImage, numObjects] = bwlabel(mask);
If you need more help, attach your reference background image - the one with no objects present.