mapbox / pixelmatch

The smallest, simplest and fastest JavaScript pixel-level image comparison library
ISC License
6.1k stars 304 forks source link

How can I group the differences or determine if there is a common change among them? #129

Closed mahiraltinkaya closed 1 year ago

mahiraltinkaya commented 1 year ago

Hello @mourner , I would like to express my gratitude for this fantastic NPM package. I am able to easily detect the differences between two images within the desired tolerance. I'm here not for a bug, but to seek advice. I hope you can assist me.

I am performing a comparison between two images: one is a white JPG image, and the other contains various green areas. While there is a significant pixel-level difference between these two images, it actually boils down to just five specific changes. My goal is to index these changes and receive a response like "it's the 3rd index" when specifying the x, y coordinates. Although I can extract the color, scanning its surroundings is a laborious task and often yields inaccurate results. The changes might have linear patterns. Therefore, I need to group them and encode where each group starts and ends along the x and y axes. Do you have any recommendations on this matter? diff

mourner commented 1 year ago

You could apply a density-based clustering algorithm such as DBSCAN to group the similar pixels. However, this is out of scope for this library.