Forum Discussion

aamer21's avatar
aamer21
Occasional Contributor
13 years ago

Problem while comparing two images

I am getting problem while comparing two images, I am geeting large difference in pixels even if both the images (one saved by me and another taken at Run time) are looking same by naked eye.

I have used "tolerence" property of "Region.Compare" but it can be used to remove small pixel difference



What should be done to remove this problem of large pixel difference in images?



It would be very nice if you help Me ASAP..My GUI testing is getting late due to this problem

Thank You.

9 Replies

  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi Aamer,


    I have used "tolerence" property of "Region.Compare" but it can be used to remove small pixel difference


    There are a few moments, I wanted to clarify.


    Region checkpoints have two parameters with similar names:

    1. Pixel Tolerance - Lets you specify the number of allowed different pixels.

    2. Color Tolerance - Lets you specify an acceptable difference for each color component.

    Which one did you specify?


    One more thing I wanted to know is: can you give us a sample image (or application) so that we could use it to reproduce the behavior? If you don't want to share your application on the forum, you can send it directly to our Support Team via the Contact Support web form.


    Thanks.

  • aamer21's avatar
    aamer21
    Occasional Contributor
    I have used pixel tolerence and it is working but if pixel difference is large then it is not good practice to use tolerence there, as even if the large difference the testing will pass.

    My problem is both the images I am comparing are looking same because I have taken it from the same application and using that for comparison, if both are same then why it is giving a problem of pixel difference?

    Is there any problem while capturing image from my side or another problem?

    Can you please tell me. Is there another way to capture the image properly same as looking in the application or another script method can be used?

    Sorry I am unable to provide the image.
  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi Aamer,


    It's difficult to say what can be wrong without seeing your image and the comparison results you get. However, I recommend that you refer to theFactors Affecting Image Comparison help topic. It contains several examples that demonstrate the situations when the image comparison fails and also describes why a certain comparison wasn't successful.


    I hope, this information helps :)

  • aamer21's avatar
    aamer21
    Occasional Contributor

    Hi Irina,


    I am posting the images and please go through the problem I am describing it below.


    I have two buttons :- FIRST-Button and SECOND-Button and Two images :- GRAY and RED color with PNG format on

    screen.

    Initially the images on the two buttons are GRAY in color and no clicks are performed.

     

    1. If TestComplete compares the two images(of FIRST-Button) without any click to it. Images are getting compared successfully.


    Now when I click FIRST-Button the GRAY image on it is replaced with RED image. When I click SECOND-Button the GRAY image on it is replaced with RED image and RED image on FIRST-Button is replaced with GRAY image.

     

    2. Now when TestComplete compares my saved FIRST-Button GRAY color image(image taken without click) with the FIRST-Button image at Run time(gray image after click). It is giving pixel difference.



    Note : Picture1 is taken by me when no click is performed.

           Picture2 is of TestComplete at Run time after click is performed on it and then SECOND-Button is clicked.    



    See to the images I have attached.

  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi Aamer,


    It seems to me that the button changes the color a little bit after you click it. The buttons may be slightly different and you may not notice it, but TestComplete will treat these images as different.


    So, I recommend that you do any of the following:

    1. Use the Color Tolerance parameter of the Region checkpoints. This parameter is used to ignore the color dissimilarity between images.

    2. Create different baseline copies for different states of the needed button (for instance, the first baseline copy contains the picture of the button before it was clicked, and the second copy contains the image of the button after you have clicked it).


    Does this help?

  • aamer21's avatar
    aamer21
    Occasional Contributor

    Hi Irina


    I have tried with the 2nd point yesterday and what I found is:


    When the first baseline copy that the picture of the button(GRAY) before click is compared with screen image without click, it is passing.


    When the first baseline copy that the picture of the button(GRAY) before click is compared with screen image after click, it is failing.


    When the second baseline copy that the picture of the button(GRAY) after click is compared with screen image after click, it is passing.


    Why this is happening and what are the possible solution to it other than 1 & 2 points of your reply.

    & can you please tell me how to use color tolerence in script?


    Is it same like Region["Compare"] or something else?


    Can you provide me an example code that compares two images - one saved by me and other test complete's runtime image that have color tolerence in it?


    Please reply soon...

    Thanks Irina for your support. You are very helpful...

  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi Aamer,


    Why this is happening
    As I have mentioned in my previous post, most likely, the button changes the color a little bit after you click on it. That's why, the comparison passes in the first and third cases you mentioned and fails in the second case.




    what are the possible solution to it other than 1 & 2 points of your reply.
    I'm afraid, I don't know other solutions.




    can you please tell me how to use color tolerence in script?
    I recommend that you use the Region.Check method. It allows comparing the item of the Regions collection with another picture (for example, a picture captured during the test run). The code below demonstrates how you can use this method:

    var BaselineImage = Regions.Item_Name;

    var RuntimeImage = <Code_You_Use_For_Capturing_Image>;

    var ColorTolerance = 15;  // This parameter takes values from 0 to 255

    var MaskObj = <Mask_Object_If_Any>;

    BaselineImage.Check(RuntimeImage, False, False, 0, ColorTolerance, MaskObj)


    Does this help?

  • aamer21's avatar
    aamer21
    Occasional Contributor
    Hi Irina,



    We are using Test Complete 6 and I think it doesn't support for 'Regions.Check' method. What should we do then?

    I also agree with you that the image is changing color with cick. Thats why we are trying to use color tolerence.

    Thanks again for your support.
  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi Aamer,


    Unfortunately, the Color Tolerance parameter was introduced in TestComplete ver. 8.0. That's why, it's impossible to use this parameter in the version you are currently using. So, you can either use the Tolerance parameter of Regions.Compare, or the second approach I suggested in one of my previous posts (create different baseline copies for different states of the tested button).