Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Surrounding Pixel Algorithm #10

Open
andrewprivate opened this issue Jun 11, 2019 · 0 comments
Open

Surrounding Pixel Algorithm #10

andrewprivate opened this issue Jun 11, 2019 · 0 comments

Comments

@andrewprivate
Copy link

andrewprivate commented Jun 11, 2019

Hello!

I am trying to learn about image comparison algorithms, and I have a question about the surrounding pixel comparison algorithm in this library.

let newColorA = this._imageA.getColorAt(currentX, currentY)
let newDeltaA = this._calculateColorDelta(colorA, newColorA)
let newColorB = this._imageB.getColorAt(currentX, currentY)
let newDeltaB = this._calculateColorDelta(colorA, newColorB)
if ((Math.abs(newDeltaB - newDeltaA) < maxDelta) && (newDeltaA > maxDelta)) {
return true
}

Particularly, I am very confused why newDeltaB is subtracted by newDeltaA to compare with the maxDelta. I feel that this may result in a false positive even with very different colors since the differences may cancel each other out in unexpected ways (I cannot really explain this well, but it is rooted in math). Also, the algorithm seems to be asymmetrical, meaning that if I switched the order of the images around, so that imageA became imageB and imageB became imageA, the results would differ greatly.

As a solution to this problem, I thought of another algorithm that could possibly work. Why wouldn't this code be a better alternative?

 let newColorA = this._imageA.getColorAt(currentX, currentY) 
 let newDeltaA = this._calculateColorDelta(colorB, newColorA) 
  
 let newColorB = this._imageB.getColorAt(currentX, currentY) 
 let newDeltaB = this._calculateColorDelta(colorA, newColorB) 
  
 if (newDeltaA < maxDelta || newDeltaB < maxDelta) { 
   return true 
 } 
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant