MATLAB Answers


How to count overlapped objects and objects with more than 1 colors in Matlab ??

Asked by farhat
on 7 Jul 2013
I want to create a program that can count the number of objects in an image. All went smoothly except for image that has:
  1. Objects that have more than 1 colors
  2. overlapping objects
Following is my program that can only count the number of objects in the image where the object is only has 1 color and not overlapped. Here is the result for image that has objects in 1 color (RIGHT RESULT)
and here is the wrong result for the image with object that has > 1 colors and overlapped (WRONG RESULT)
I use the function "bwlabel"
a=imread('Tumpukan Buku2.jpg');
a_citra_keabuan = rgb2gray(a);
threshold = graythresh(a_citra_keabuan);
a_bww = im2bw(a_citra_keabuan,threshold);
s = regionprops(labeled, 'Centroid');
B = bwboundaries(a_bw);
hold on
for k = 1:numel(s)
c = s(k).Centroid;
text(c(1), c(2), sprintf('%d', k), ...
'HorizontalAlignment', 'center', ...
'VerticalAlignment', 'middle');
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'g', 'LineWidth', 0.2)
hold off
Is it true that i cannot do segmentation for various objects with the same code?? so i have to define the shape of objects that i want to segment and count before, and with the same code i cannot segment and count the object FOR EXAMPLE BETWEEN the image of pinguins with image of ball?
Please help me to solve it..


Sign in to comment.

1 Answer

Answer by Image Analyst
on 7 Jul 2013

I don't know what a "pinguin" is. The only image I saw that had a ball (a disc) was the first image, so maybe pinguin means objects or patches or color regions or polygons or whatever.
Of course you can't characterize of books in your second image without some higher level knowledge. Like the fact that a book is a rectangular block in 3D, and how many books there are, etc. For example, the bottom dark blue book could be 1 book but it's also consistent with 2 or 3 books.


Pinguins is an example of my other object. I mean can we detect how many pinguins in the image and ammount of a balls (In other image) with same code?
For the book image, we cannot count how many book in the image because book in the image is in 3D form? And we just can detect ammount of the object for the 2D images, is it right??
I still don't know what a pinguin is, and doesn't know either. Anyway, you can find colored patches. Anything beyond that, in 3D, for that image, like I said, will require higher level knowledge, and not be easy.

Sign in to comment.