HumbleSoftware / js-imagediff

JavaScript / Canvas based image diff utility with Jasmine matchers for testing canvas.
http://humblesoftware.github.com/js-imagediff/
MIT License
788 stars 99 forks source link

Provide a global tolerance when comparing for equality #36

Open cburgmer opened 10 years ago

cburgmer commented 10 years ago

This PR tries to solve #18.

As proposed it implements an optional parameter set along the following example:

{
  tolerance : 0.05,
  totalTolerance : true
}

Following those changes imagediff.equal(a, b, 128) would be expressed through imagediff.equal(a, b, {tolerance: 0.5}) in the future (however the old API remains intact). A global tolerance can be given through adding totalTolerance: true to the option object.

cburgmer commented 10 years ago

My thoughts: I did want to follow your suggestion and see how things pan out. However, I am not happy with the API. There are a few things:

Will try to come up with an alternative idea.

cburgmer commented 10 years ago

Here's my current proposal:

imagediff.equal(a, b, {toleranceValue: 5, toleranceMethod: 'relativePerPixel'});

and

imagediff.equal(a, b, {toleranceValue: 0.25, toleranceMethod: 'totalRatio'});
cesutherland commented 10 years ago

Can you give me an example of relativePerPixel? Would that be a total difference of 5 across the rgba values for a single pixel?

cburgmer commented 9 years ago

Sorry for the late response.

relativePerPixel is the current implementation, where any pixel maybe different as long as it each absolute difference stays below the threshold.

totalRation is what I'd like to add, where an accumulated difference is used.

I'm not sure about the proposed API anymore though. I think it would be easier if we'd provide a method on it's own for the different tolerances?