tim
tim

Reputation: 10176

Matlab: Search for center of objects in binary image

I have an image like the following:

binary img

It's plotted via imshow(I) and I is a logical matrix, you can get this one from here: http://pastebin.com/qsxA0GXy

Those objects are mostly something like a rough circle, but they also can be some sort of eliptic of about three times greater in size.

I want to find the coordinates of the center of those objects, but only estimated. I dont want to use a circular hough transform as I need only a estimated value and I need a fast algorithm.

My idea was: Loop each pixel and if it's a true value, search all neighboor-pixel which are also true and than get the center of the object by calculating

x = x_max - xmin;

y = y_max - ymin;

but I dont like this approach as it seems quite slow for me with using 2 nested for loops. Anything nicer you can think of? thanks!

Upvotes: 1

Views: 4919

Answers (2)

Geodesic
Geodesic

Reputation: 893

This seems to be quite fast. Not too sure how it'll scale though:

L = bwlabel(I);
stats = regionprops(L,I,'Centroid');

Upvotes: 2

Spectre
Spectre

Reputation: 684

Try the concept used in this answer: https://stackoverflow.com/a/2242565/845528

I tried it (by saving the image you have provided above. I didn't go to the link you provided). It seems to work:

    Image = imread('im.jpg');
    dImage = im2double(Image);
    logicalImage = im2bw(dImage, 0.5);

    dilatedImage = bwmorph(logicalImage, 'shrink',Inf);
    [x,y] = find(dilatedImage);

Upvotes: 0

Related Questions