Thank you.
I also experimenting with AverageHash, is that available too?
The version I created using this API bombs on really large images (10000 x 8000). I'm on my iPad or I'd post the code. But basically it's...
So, where it bombs, I use a thumbnail created with a GDI routine I made years ago. It would bomb with the image.Thumbnail(same geometry object) as well. Kept getting Memory allocation errors.
Then to compare two images, you compare their hashes, would be the same with PHash. You compare the bits and the more differences the less likely the image is similar. There are probably better ways than the below to compute the Hamming Distance.
I also experimenting with AverageHash, is that available too?
The version I created using this API bombs on really large images (10000 x 8000). I'm on my iPad or I'd post the code. But basically it's...
using(var image = new MagicImage(file))
{
// Need the 8x8 image for 64 bits of information
image.Resize(new MagicGeometry(8) { MaintainAspectRatio = false }); // bombs here
image.Grayscale(forget the settings, but is is the enum.Undefined); // which would be nice as image.Grayscale() with no parameters...
var colors = image.Pixels // forget exact property
.Select(p => p.GetChannel(0).Value)
.ToList();
long average = colors.Average();
var bits = colors.Select(c => c >= average); // bits as bool vaues
// convert bits to Int64
// I do it with a BitArray, but I saw a slicker version somewhere that does it with bitwise, but I was unsure how to convert back
return theNewInt64;
}
Because of the image.Resize() failing, and having to use a separate libary image to create the AverageHash, I don't think it works correctly. That's why if ImageMagic has the AverageHash, to gain access to it would be helpful.So, where it bombs, I use a thumbnail created with a GDI routine I made years ago. It would bomb with the image.Thumbnail(same geometry object) as well. Kept getting Memory allocation errors.
Then to compare two images, you compare their hashes, would be the same with PHash. You compare the bits and the more differences the less likely the image is similar. There are probably better ways than the below to compute the Hamming Distance.
int HammingDistance(Int64 a, Int64 b)
{
var bitsA = Convert64ToBits(a); // Convert the Int64 back to an array of bools
var bitsB = Convert64ToBits(b);
int count = 0;
for(int i = 0;i < 64;i++)
if(bitsA[i] != bitsB[i]) count++;
return count;
}