2

I'm doing some low level image processing project and I need to locate the position of an object. In this case it's a comet. I played a bit with the thresholds and got a pretty much binary image, but what I need next is to locate a fixed point in the middle of the large group of white pixels so it can be traced or something. Any idea on how to do that? Here's a screen shot of what I got.

enter image description here

Link to the photo

And is there a way to filter out all the white dots all over the picture? Some kind of function to give all small groups value of "0"? Thanks in advance!

Divakar
  • 218,885
  • 19
  • 262
  • 358
Martin V
  • 55
  • 1
  • 2
  • 6

4 Answers4

3

Maybe you are looking for this -

Code

%%// Read in image and convert to binary
img = imread(IMAGE_FILEPATH);
BW = im2bw(img);

%%// Get only the comet blob, which is the biggest blob
[L, num] = bwlabel(BW);
counts = sum(bsxfun(@eq,L(:),1:num));
[~,ind] = max(counts);
BW = (L==ind);

%%// Find the centroid of the comet blob
stats = regionprops(BW, 'Centroid');
center_point = stats.Centroid

Output

center_point =

   56.7471  131.9373

enter image description here

Note: There's another question - Select largest object in an image that relates to this case.

Community
  • 1
  • 1
Divakar
  • 218,885
  • 19
  • 262
  • 358
  • Thanks a lot, it works perfectly! Just, how did you get that window with the coordinates to pop up? Was it in the code or you opened it afterwards on the plot? – Martin V Apr 11 '14 at 12:07
  • 1
    That's a data cursor. You can get it right on the figure window when you use imshow. Read more about it [here](http://www.mathworks.in/help/matlab/creating_plots/data-cursor-displaying-data-values-interactively.html) – Divakar Apr 11 '14 at 12:10
  • @MartinV Consider accepting answers that have fullfiled the expectations from questions, it helps `SO` community at large. Read more about accepting answers here - http://stackoverflow.com/help/accepted-answer – Divakar Apr 11 '14 at 16:50
2

MATLAB regionprops is your friend, and your image is good enough for what you want to do.

regionprops does just what you need (you get the X,Y of the center of mass). Since it also gives the area, you can filter results and only retain the largest object in your image.

Jean-Yves
  • 699
  • 1
  • 11
  • 22
1

Your problem seems to be solved with regionprops, as others have proposed already, but if you're interested, in general, in eliminating small white artefacts in an image:

You could apply one or multiple steps of erosion to your binary image, eliminating small white spots (but also decreasing the size of your comet!).

Lisa
  • 3,365
  • 3
  • 19
  • 30
0

you can use a median filter or a morphological opening filter to remove small white regions. you'll have to experiment and pick the right size for the filter kernel. assuming you have a cleaner image after filtering, you can perform a labeling and then do a regionprops to get the centroid of the blob.

dhanushka
  • 10,492
  • 2
  • 37
  • 47