how to detect objects in a box in a greyscale image

7 views (last 30 days)
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.

Accepted Answer

Image Analyst
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.
  3 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!