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

Error when two images are identical #1

Closed
RezaRahmati opened this issue Jan 18, 2016 · 3 comments
Closed

Error when two images are identical #1

RezaRahmati opened this issue Jan 18, 2016 · 3 comments

Comments

@RezaRahmati
Copy link

If tow images are identical you will get an exception for fixing that I changed Compare method to this

    public Bitmap Compare(Bitmap firstImage, Bitmap secondImage)
    {
        if (firstImage == null) throw new ArgumentNullException("firstImage");
        if (secondImage == null) throw new ArgumentNullException("secondImage");
        if (firstImage.Width != secondImage.Width || firstImage.Height != secondImage.Height) throw new ArgumentException("Bitmaps must be the same size.");

        var differenceMap = BitmapAnalyzer.Analyze(firstImage, secondImage);

        if (differenceMap.Cast<bool>().Any(i => i))
        {

            var differenceLabels = Labeler.Label(differenceMap);
            var boundingBoxes = BoundingBoxIdentifier.CreateBoundingBoxes(differenceLabels);
            var differenceBitmap = CreateImageWithBoundingBoxes(secondImage, boundingBoxes);
            return differenceBitmap;
        }
        return null;
    }

and even I used the side effect, when they are identical I get the null as result.

@richclement
Copy link
Owner

Thanks for the logged issue. I see the root cause is in IBoundingBoxIdentifier implementation. I will update the code to fix this and not change the return options for Compare.

@RezaRahmati
Copy link
Author

@richclement Thanks for fast response, so by this change, how we can find out that the files were identical?
in our project we want to save the difference and throw exception if they are not identical and do nothing if they are identical.

@richclement richclement reopened this Jan 19, 2016
@richclement
Copy link
Owner

I can add an additional method to the IImageComparer interface. Something like bool Equals(T firstImage, T secondImage). This would use the IBitmapAnalyzer strategy that the Comparer is initialized with and effectively short circuit the processes after analyzing the images. This would avoid labeling and building bounding boxes for the image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants