Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] mergeRectangles hangs #201

Closed
HoverCatz opened this issue Dec 17, 2020 · 9 comments
Closed

[BUG] mergeRectangles hangs #201

HoverCatz opened this issue Dec 17, 2020 · 9 comments
Assignees
Labels
bug Something isn't working
Projects

Comments

@HoverCatz
Copy link

HoverCatz commented Dec 17, 2020

Describe the bug
The program hangs forever.

To Reproduce
Steps to reproduce the behavior:

  1. Download attached zip and extract the 2 image files anywhere.
    files.zip
  2. Run this code:

ImageComparison comparison = new ImageComparison("output_153.png", "output_154.png");
comparison.createMask(); // hangs forever

Expected behavior
Program should run and exit appropriately.

Screenshots
See attached zip above

Java

  • OS: Windows
  • openjdk version "1.8.0_252"

Additional context
I managed to trace this to the method mergeRectangles.
I don't know why it hangs, but I debugged it and the (minimum and maximum rectangles) are equal to the image size (width*height).
I (thought I) fixed it (see my comment) by skipping running mergeRectangles in a special scenario:

private List<Rectangle> populateRectangles() {
        long countOfDifferentPixels = populateTheMatrixOfTheDifferences();

        if (countOfDifferentPixels == 0) {
            return emptyList();
        }

        if (isAllowedPercentOfDifferentPixels(countOfDifferentPixels)) {
            return emptyList();
        }
        groupRegions();
        List<Rectangle> rectangles = new ArrayList<>();

        int minX = Integer.MAX_VALUE, minY = Integer.MAX_VALUE, maxX = Integer.MIN_VALUE, maxY = Integer.MIN_VALUE;

        while (counter <= regionCount) {
            Rectangle rectangle = createRectangle();
            if (!rectangle.equals(Rectangle.createDefault()) && rectangle.size() >= minimalRectangleSize) {
                rectangles.add(rectangle);
                Point min = rectangle.getMinPoint();
                Point max = rectangle.getMaxPoint();
                if (min.x < minX) minX = min.x;
                if (min.y < minY) minY = min.y;
                if (max.x > maxX) maxX = max.x;
                if (max.y > maxY) maxY = max.y;
            }
            counter++;
        }

        if (minX == 0 && minY == 0 &&
            maxX == actual.getWidth() - 1 &&
            maxY == actual.getHeight() - 1)
            return Collections.singletonList(new Rectangle(0, 0, maxX, maxY));

        return mergeRectangles(rectangles);
    }

(I don't feel comfortable making a pull request).

@HoverCatz HoverCatz added the bug Something isn't working label Dec 17, 2020
@HoverCatz
Copy link
Author

Not a permanent fix, not even close.
Just got this issue again somewhere else (2 other frames), it just hangs forever.
Damn thought I found a fix, my bad.
Still needs fixing.

@romankh3
Copy link
Owner

Hello, @HoverCatz.
Thanks for your contributions.
I will see what can I do with it.

Best regards,
Roman.

@romankh3
Copy link
Owner

romankh3 commented Mar 1, 2021

Hi @HoverCatz.
You know, it's totally different images. image-comparison doesn't use for it.

@romankh3 romankh3 closed this as completed Mar 1, 2021
@HoverCatz
Copy link
Author

Yes ofc they are different. image-comparison should recognize this and not hang itself...

@romankh3 romankh3 reopened this Mar 1, 2021
@romankh3
Copy link
Owner

romankh3 commented Mar 1, 2021

I got it, thanks. We need to recognize it and stop comparing

@HoverCatz
Copy link
Author

Thank you! 🥇

@romankh3 romankh3 added this to To do in 4.5.0 via automation Mar 1, 2021
romankh3 pushed a commit that referenced this issue Mar 13, 2021
Fix bug #201
romankh3 pushed a commit that referenced this issue Mar 13, 2021
4.3.1: Fix bug #201
@romankh3
Copy link
Owner

@HoverCatz, bug fixed in 4.3.1 version.
Thanks, that you found a bug, investigate the place in which the problem is and create a bug report with provided images.

If you have any ideas of how to improve image-comparison feel free to write me about it.

Best regards,
Roman.

4.5.0 automation moved this from To do to Done Mar 13, 2021
@HoverCatz
Copy link
Author

I had a question! Is it possible to implement support to detect when 2 images are "almost" identical? For example randomized JPEG compression on the same image. The original images are the same, but the pixels aren't anymore thanks to compression. Hope you understand! 💯

@romankh3
Copy link
Owner

Hi, @HoverCatz.
I think this page can help you with you question: https://github.com/romankh3/image-comparison/wiki/Image-Comparison-with-Image-compression

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
4.5.0
  
Done
Development

No branches or pull requests

2 participants