5

I have these images to compare with each other. However, there are too many blacks that I think I can crop out to make comparison more effective.

Mars 1 Mars 2 Mars 3

What I want to do is crop Mars. Rectangle or round whichever may yield better results when compared. I was worrying that if the cropping would result to images of different sizes, comparison wouldn't work out as well as expected? Ideas how to do it and sample codes if possible? Thanks in advance

UPDATE: Tried using cvHoughCircles() it won't detect the planet :/

Masochist
  • 389
  • 2
  • 7
  • 16
  • When did you take these pictures? Mars is pretty deep in the sunset right now since it's about to go into Solar Conjunction. – Mysticial Jan 28 '13 at 05:59
  • Threshold, [detect connected component][1], crop image. Done. [1]: http://stackoverflow.com/questions/6044119/opencv-cvfindcontours-how-do-i-separate-components-of-a-contour – LovaBill Jan 28 '13 at 12:09

3 Answers3

6

Try to use color detection. You need to find all the colors except black. Here and here are nice explanations of this method.

optional
  • 2,504
  • 4
  • 18
  • 30
Ann Orlova
  • 1,338
  • 15
  • 24
4

You can convert these images to gray scale images using cvCvtColor(img,imgGrayScale,CV_BGR2GRAY)

Then threshold them using cvThreshold(imgGrayScale,imgThresh,x,255,CV_THRESH_BINARY). Here, you have to find a good value for x(I think x=50 is ok).

CvMoments *moments = (CvMoments*)malloc(sizeof(CvMoments));
cvMoments(imgThresh, moments, 1);
double moment10 = cvGetSpatialMoment(moments, 1, 0);
double moment01 = cvGetSpatialMoment(moments, 0, 1);
double area = cvGetCentralMoment(moments, 0, 0);
int x = moment10/area;
int y = moment01/area;

Now you know the (x.y) coordinate of the blob. Then you can crop the image using cvSetImageROI(imgThresh, cvRect(x-10, y-10, x+10, y+10)). Here I have assumed that the radius of this blob is less than 10 pixel.

All cropped images are of same size and the white blob (planet) is exactly at the middle of the image.

Then you can compare images using normalized cross-correlation.

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
SRF
  • 929
  • 1
  • 7
  • 15
  • Hi! The ROI idea was great. Will you help me set my bounded box as my ROI? http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/bounding_rects_circles/bounding_rects_circles.html – Masochist Jan 29 '13 at 15:49
  • It is easy to set ROI using `cvSetImageROI` function. But you can use 1 ROI for single image. – SRF Jan 29 '13 at 16:15
1

There's no fundamental reason why a histogram would fail here. I would convert the image to greyscale before doing a histogram, just to make the numbers more manageable. A color image has a 3D histogram; the Red, Green, Blue and Greyscale histograms are all 1D projections of that 3D histogram.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • I'm sorry I must have included unnecessary info. What I wanted to do was to compare without the blacks. – Masochist Jan 29 '13 at 09:25