Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9257609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:11:21+00:00 2026-06-18T12:11:21+00:00

I am trying to automatically decide wether two figures are similar or not. You

  • 0

I am trying to automatically decide wether two figures are similar or not. You can find three examples here:
https://i.stack.imgur.com/09Zqf.png

The first image is different from the second and third image, but the second and third are the same (not identical, if you look closely, there are some small differences)

My code (most of it is from the feature homography example in the OpenCV documentation) reads two different images, computes their keypoints and descriptors (using SIFT, but I have also tried SURF and ORB), matches them using the FlannBasedMatcher and computes the homography matrix. From the optional status vector I compute the ratio of inliers over the total number of keypoints in order to compute a ‘distance’.

However, the distances calculated do not make the correct distinction:

d(img1, img2) = 0.296296
d(img1, img3) = 0.407407
d(img2, img3) = 0.362069

So I am unable to conclude that image 1 is different from image 2, image 1 is different from image 2 and image 2 is equal to image 3.

Is there a better method or metric to decide which images are similar?

Mat img_object = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
Mat img_scene = imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );

//-- Step 1: Detect keypoints using SIFT
Ptr<FeatureDetector > detector;
detector = new SiftFeatureDetector();
std::vector<KeyPoint> keypoints_object, keypoints_scene;
detector->detect( img_object, keypoints_object );
detector->detect( img_scene, keypoints_scene );

//-- Step 2: Calculate descriptors (feature vectors)
Ptr<DescriptorExtractor > extractor;
extractor = new SiftDescriptorExtractor;
Mat descriptors_object, descriptors_scene;
extractor->compute( img_object, keypoints_object, descriptors_object );
extractor->compute( img_scene, keypoints_scene, descriptors_scene );

//-- Step 3: Matching descriptor vectors using FLANN matcher
FlannBasedMatcher matcher;
std::vector< DMatch > matches;
matcher.match( descriptors_object, descriptors_scene, matches );

//-- Step 4: Compute homography matrix and status vector
std::vector<Point2f> obj;
std::vector<Point2f> scene;
for( int i = 0; i<matches.size(); i++){
    obj.push_back( keypoints_object[ matches[i].queryIdx ].pt );
    scene.push_back( keypoints_scene[ matches[i].trainIdx ].pt );
}
std::vector<uchar> status;
Mat H = findHomography( obj, scene, status, CV_RANSAC, 3 );

//-- Step 5: Compute inliers/status.size
int inliers = 0;
for(int i = 0; i<status.size(); i++){
    inliers += status[i];
}
printf("Percentage of inliers: %f \n",( (float) inliers)/( (float) status.size() ));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:11:21+00:00Added an answer on June 18, 2026 at 12:11 pm

    Is there a better method or metric to decide which images are similar?

    Why don’t you just find all circles and calculate distance between them?

    Here’s code:

    Point2i center(vector<Point2i> contour)
    {
        Moments m = moments(contour);
    
        return Point2i(m.m10/m.m00, m.m01/m.m00);
    }
    
    
    vector<Point2i> getCenters(Mat img)
    {
        vector<vector<Point2i> > contours;
    
        threshold(img, img, 0, 255, THRESH_OTSU);
    
        findContours(img, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
    
        vector<Point2i> result(contours.size());
    
        for (int i=0; i<contours.size(); i++)
        {
            result[i] = center(contours[i]);
        }
    
        return result;
    }
    
    
    double distanceCenter(Point2i center1, Point2i center2)
    {
        return (center1.x - center2.x)*(center1.x - center2.x) + (center1.y - center2.y)*(center1.y - center2.y);
    }
    
    
    double distanceCenters(vector<Point2i> centers1, vector<Point2i> centers2)
    {
        if (centers1.size() != centers2.size())
        {
            return -1;
        }
        else
        {
            double result = 0;
    
            for (int i=0; i<centers1.size(); i++)
            {
                double min = INT_MAX;
    
                for (int j=0; j<centers2.size(); j++)
                {
                    double dist = distanceCenter(centers1[i], centers2[j]);
                    if (dist < min)
                    {
                        min = dist;
                    }
                }
    
                result += min;
            }
    
            return result;
        }
    }
    
    
    int main()
    {
        Mat img1 = imread("image1.png", CV_LOAD_IMAGE_GRAYSCALE),
            img2 = imread("image2.png", CV_LOAD_IMAGE_GRAYSCALE);
    
        cout << distanceCenters(getCenters(img1), getCenters(img2)) << endl;
    
        return 0;
    }
    

    And results:

    distance between 1 and 2: 14676

    distance between 2 and 3: 393

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How I can expand stack automatically when needed? (Until max I decide) I am
I'm trying to decide between two ways of instantiating an object & handling any
The actual problem I'm trying to solve is, I want to automatically find out
I am trying to automatically draw in a program similar to paint by simulating
I'm trying to automatically select a menu item in iTunes using applescript. However, every
I am trying to automatically log in users to an Xwiki install via basic
I'm trying to automatically compress both CSS and JS using maven and this plugin
I am trying to automatically figure out which Delphi version (of Delphi 5 to
I'm trying to login automatically in a website using Perl with WWW::Mechanize . What
i am trying to run a PHP automatically on a server every 15 minutes.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.