Compare 2 images via RGB values

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By yukkitimmy

Hey Guys!

Im working on a programm that compares two 16x16 tiles of an image to see if they are unique to each other.

But the approach I am using right now is a little bit flawed.

I am looping through every pixel of a tile and add the RGB values of each together, but this leads to the problem that i cant distinguish the location of the pixels, if for example the tiles have the same amount of black and white pixels but in another location.

Is there any way to add the RGB values together so that the location of the individual pixels are considered?

Or even better is there another way to compare two tiles with each other?

Can you show us the code of your compare-method?

whiteshampoo | 2021-01-25 13:16

:bust_in_silhouette: Reply From: Calinou

To achieve what you want, you may have to implement an image similarity algorithm like SSIM/DSSIM in GDScript. This algorithm isn’t trivial, so you’ll probably have to look at a Python library implementing it and port it to GDScript.

Alternatively, if you’re certain that the images are in the same format, you could compare the checksums of the image data’s PoolByteArrays.