Forum Discussion

rushikesh's avatar
rushikesh
Contributor
6 years ago
Solved

Is there a way to measure how much an image differs from compared image ?

Hello,

 

I have two images say A and B.

There is a baseline image say Z.

 

I want to compare A with Z and find out how much A differs from Z. ( like in percentage or particular number)

 

then I want to compare B with Z and find out how much B differs from Z.

 

My requirement is not know which image ( A or B ) is more similar to Z.

 

I am using JavaScript.

 

Is there a way to this in Test Complete?

 

 

Any help is appreciated.

 

Regards,

Rushikesh Kadam.

  • Based on the images provided...

     

    Do some math to determine the center of the image.  Using the Pixels function, which is a method of Picture (https://support.smartbear.com/testcomplete/docs/reference/program-objects/picture/pixels.html?q=pixels), retrieve the color at the middle.  If it's your shade of blue, it's pinned.  If it's that shade of gray, it's unpinned.

     

    Retrieving the amount of red is a similar process.  You're going to loop through each pixel in the image and if the pixel color is red, increment a red counter.  It's not elegant, but it'll get the job done.

     

    I think your best bet is to test for blue or gray.

10 Replies

  • Based on the images provided...

     

    Do some math to determine the center of the image.  Using the Pixels function, which is a method of Picture (https://support.smartbear.com/testcomplete/docs/reference/program-objects/picture/pixels.html?q=pixels), retrieve the color at the middle.  If it's your shade of blue, it's pinned.  If it's that shade of gray, it's unpinned.

     

    Retrieving the amount of red is a similar process.  You're going to loop through each pixel in the image and if the pixel color is red, increment a red counter.  It's not elegant, but it'll get the job done.

     

    I think your best bet is to test for blue or gray.

  • My first question is why you need to know which one is more similar, but that's only for personal edification.

     

    The Regions object at https://support.smartbear.com/testcomplete/docs/reference/project-objects/items/stores/regions/index.html contains two methods, Compare and Difference.  You could use the Compare method to determine if they match, and then use the results from the Difference object to count the number of red pixels to determine which image (A or B) has more red in it, indicating more differences.

     

    It's not an optimal or pretty approach, but it should work.

    • rushikesh's avatar
      rushikesh
      Contributor

      will_fetherolf 

      I am testing a CAD application. Here I am facing problem in recognizing the state of a pin button. Refer attached images for pin button and two state of this button ( Pin button is used to pin dialog so that it does not close on clicking on OK and reappears with initial state. )

      Test complete does not give state of this Pin button. i.e. if button is in pin or unpin.

       

      So thought will compare images of both these state to know if button is pinned or unpinned.

      I cannot directly compare image of state with either pin or unpin image as test will be running on different machines with different resolutions, on each machine image of respective state will vary slightly.

       

      Requirement is to compare current state of button on a particular machine with already saved pin and unpin image. Get how much current state image differs from saved pin and unpin images. One which gives minimum difference will indicate state of button.

       

       

       

    • rushikesh's avatar
      rushikesh
      Contributor

      will_fetherolf

      Also, can you specify how to count the number of red pixels to determine which image (A or B) has more red in it, indicating more differences ?

      • baxatob's avatar
        baxatob
        Community Hero

        rushikesh wrote:

         


        ...Test complete does not give state of this Pin button...

         


        Probably Pin and Unpin buttons - are different objects. E.g. they have different values for Class (or ClassName) property. Can you check this?