giving index numabers to objects in an image

2 views (last 30 days)
HEllo,I want to give index numbers to objects in an image like 1,2..... when we are detecting the objects in an image using canny detection algorithm.Is it possible.Thanks in advance!!!!

Answers (1)

Image Analyst
Image Analyst on 22 Jul 2015
Please post your image. You would not believe the number of people who think edge detection is the first step in an image processing algorithm when it's actually not even appropriate, or the best approach. It seems like the whole world thinks edge detection is the approach to use first before all others. It's usually not .
Anyway, you can attach numbered labels to the objects with bwlabel or bwconncomp:
labeledImage = bwlabel(binaryImage);
  5 Comments
yashwine ganji
yashwine ganji on 29 Jul 2015
Edited: yashwine ganji on 29 Jul 2015
Please give me the code for detecting the objects in that image and display them separately in windows.
Image Analyst
Image Analyst on 29 Jul 2015
You can easily do this with the Image Segmentation tutorial I gave. You just need to add the ConvexHull to what you measure.
[labeledImage, numObjects] = bwlabel(binaryImage);
measurements = regionprops(labeledImage, 'ConvexHull');
Then pick out some number - you can put this in a loop if you want - and use its convex hull as a mask on the original image to extract just that object.
for k = 1 : numObjects
thisObjectMask = measurements(k).ConvexHull;
% Mask the image.
maskedRgbImage = bsxfun(@times, rgbImage, cast(thisObjectMask, class(rgbImage)));
figure;
imshow(maskedRgbImage);
end
Or something like that.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!