Ask Your Question
0

Can you please tell me a good comparision method for comparining the below two images

asked 2016-06-29 23:21:41 -0600

raja1018 gravatar image

Tests done 1.HSV histograms -- failed 2.Color histograms -- failed (huge difference in colors) 3.ORB detectors and descriptors , BF matchers -- did not work changed the patch size but still could not find desired results. 4.MSER keypoints and ORB descriptor and BF matcher still could differentiate

IMAGE-1 image description IMAGE-2 image description

edit retag flag offensive close merge delete

Comments

1

This seems a Bag of Visual words - solvable problem. Tons of guides showing you how to do that!

StevenPuttemans gravatar imageStevenPuttemans ( 2016-06-30 06:26:29 -0600 )edit

Do I need to train the vocabulary for BoW descriptor

raja1018 gravatar imageraja1018 ( 2016-06-30 10:04:35 -0600 )edit

Yep you do :)

StevenPuttemans gravatar imageStevenPuttemans ( 2016-06-30 13:43:30 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
4

answered 2016-07-01 05:55:13 -0600

pklab gravatar image

updated 2016-07-01 11:59:41 -0600

Because images looks very similar you could try matchTemplate. Cross Correlation is quite invariant to brightness variation and using TM_CCORR_NORMED method you can get a 0..1 score for the matching.

Using this code I get score=91.6% comparing your images and score=79.4% comparing 2 completely different images.

int main()
{
  Mat img1, img2;
  img1=imread("img1.jpg");
  img2=imread("img2.jpg");
  //with TM_CCORR, normalization doesn't improve score so much 
  //but convert to gray improves speed 
  cvtColor(img1, img1, CV_BGR2GRAY);
  cvtColor(img2, img2, CV_BGR2GRAY);

  //resize to the smallest
  //resize big images to improve speed
  //this steps can be optimized
  if (img1.size().area() < img2.size().area())
    cv::resize(img2, img2, img1.size());
  else
    cv::resize(img1, img1, img2.size());
  if (img1.size().area() > 800 * 800)
  {
    cv::resize(img1, img1, Size(0, 0), 0.5, 0.5);
    cv::resize(img2, img2, Size(0, 0), 0.5, 0.5);
  }
  Mat matchResult(Size(1, 1), CV_32F);
  matchTemplate(img1, img2, matchResult, TM_CCORR_NORMED);
  double score = matchResult.at<float>(0, 0);
  // Sincerely match 2 completely different images gives score~0.8
  if (score > 0.9)
    cout << "Match with score " << 100.0*score << "%" << endl;
  else
    cout << "NOT match. score =" << 100.0*score << "%" << endl;
  return 0;
}
edit flag offensive delete link more

Comments

Template matching did work but I had to use cv2.TM_CCOEFF_NORMED as TM_CCORR_NORMED showed me it was a match with other random images

raja1018 gravatar imageraja1018 ( 2016-07-11 09:53:16 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-06-29 23:21:41 -0600

Seen: 855 times

Last updated: Jul 01 '16