Skip to content

ignoreRectangles feature #9

Closed
Closed

Description

@curtw

Proposing to add "ignoreRectagles" feature as in node-resemble-js, where options would support an ignoreRectangles property which is as in resemble:

//array of rectangles, each rectangle is defined as (x, y, width, height)
//e.g. [[325, 170, 100, 40]]

Pixels within these rectangles would not be tested. Unsure of best way to represent these in diff image.

Activity

  1. mourner commented on Nov 17, 2015

    @mourner
    Member

    I wonder whether it's worth introducing complexity with features like this, or just leaving this up to the user since it's easy enough to just iterate over and null all pixels in desired areas in both input images.

  2. curtw commented on Nov 22, 2015

    @curtw
    Author

    I did a quick implemenation that builds a hash from the rectanges, and then tests the hash with each iteration of the comparison loop:

    function buildIgnoreHash(rectangles) {
        var hash = {};
        for (var i=0; i<rectangles.length; i++) {
            var x1=rectangles[i][0],
                x2=rectangles[i][2]+x1,
                y1=rectangles[i][1],
                y2=rectangles[i][3]+y1;    
    
            for (var y = y1; y < y2; y++) {
                for (var x = x1; x < x2; x++) {
                    hash[x]=hash[x]||{};            
                    hash[x][y]=true;
                }
            }
        }
        return hash;
    }
    

    if (ignoreHash && ignoreHash[x] && ignoreHash[x][y])
        continue;
    

    Surprising to me, it was not any faster than blanking out rectanges in both images. The only advantage of adding ignoreRectangles feature to the package is that is non-destructive, so you can do something else with the images after comparing them.

  3. curtw commented on Dec 10, 2015

    @curtw
    Author

    Another advantage of including this feature in the package is that the color of the ignore rectangles could be set to black in the diff image, making it clear what had been excluded from the comparison.

    if (ignoreHash && ignoreHash[x] && ignoreHash[x][y]) {
        drawPixel(output, pos, 0, 0, 0);
        continue;
    }
    

    Setting the color to black in the input images does not produce a diff image that adequately distinguishes ignore rectangles from darker parts of the input images.

    You could black-out the resulting diff image as well, but that's getting a be a lot of extra steps.

  4. skyiea commented on Dec 24, 2017

    @skyiea

    Hi.
    Any plans to introduce this feature?

  5. mourner commented on Dec 24, 2017

    @mourner
    Member

    No plans for now, to keep it simple. There's a workaround:

    it's easy enough to just iterate over and null all pixels in desired areas in both input images

  6. adamchenwei commented on Apr 9, 2019

    @adamchenwei

    @mourner any example code how to do that? sorry pretty new to pixelmatch!

  7. mourner commented on Jun 6, 2019

    @mourner
    Member

    A sample snippet of how to clear pixel data in a rectangular region (x0, y0, x1, y1):

    for (let y = y0; y < y1; y++) {
        for (let x = x0; x < x1; x++) {
            const k = 4 * (width * y + x);
            data[k + 0] = 0;
            data[k + 1] = 0;
            data[k + 2] = 0;
            data[k + 3] = 0;
        }
    }
  8. added a commit that references this issue on Sep 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions