Giter Site home page Giter Site logo

Any difference? about imagehash HOT 5 CLOSED

coenm avatar coenm commented on June 15, 2024
Any difference?

from imagehash.

Comments (5)

LambertWM avatar LambertWM commented on June 15, 2024

Interesting !
In what way are the results from pHash better than ImageHash?

from imagehash.

developervariety avatar developervariety commented on June 15, 2024

Thank you for the response.

I use pHash to compare similar images for a a service I try to automate. With the result of pHash I take the image and submit it to the service. For some reason, the results from this library are almost always incorrect.

It confuses me on why exactly they are incorrect if they are both based off the same library. I will provide some data so you can test for yourself, shortly.

from imagehash.

developervariety avatar developervariety commented on June 15, 2024

Maybe @pgrho could look into this whenever they have free time on their hands.

More context, I compare images with all colors made black. The only white part is the transparency if that makes any sense.

from imagehash.

pgrho avatar pgrho commented on June 15, 2024

@developervariety My pHash creates an intermediate image of 32x32 pixels to calculate DCT, but 64x64 in the ImageHash. So they seems to be incompatible.

private const int Size = 64;
private static readonly double Sqrt2DivSize = Math.Sqrt(2D / Size);
private static readonly double Sqrt2 = 1 / Math.Sqrt(2);
/// <inheritdoc />
public ulong Hash(Image<Rgba32> image)
{
if (image == null)
throw new ArgumentNullException(nameof(image));
var rows = new double[Size][];
var sequence = new double[Size];
var matrix = new double[Size][];
image.Mutate(ctx => ctx
.Resize(Size, Size)
.Grayscale(GrayscaleMode.Bt601)
.AutoOrient());
// Calculate the DCT for each row.
for (var y = 0; y < Size; y++)
{
for (var x = 0; x < Size; x++)
sequence[x] = image[x, y].R;
rows[y] = Dct1D(sequence);
}
// Calculate the DCT for each column.
for (var x = 0; x < Size; x++)
{
for (var y = 0; y < Size; y++)
sequence[y] = rows[y][x];
matrix[x] = Dct1D(sequence);
}
// Only use the top 8x8 values.
var top8X8 = new List<double>(Size);
for (var y = 0; y < 8; y++)
{
for (var x = 0; x < 8; x++)
top8X8.Add(matrix[y][x]);
}
var topRight = top8X8.ToArray();
// Get Median.
var median = CalculateMedian64Values(topRight);
// Calculate hash.
var mask = 1UL << (Size - 1);
var hash = 0UL;
for (var i = 0; i < Size; i++)
{
if (topRight[i] > median)
hash |= mask;
mask = mask >> 1;
}
return hash;
}

https://github.com/pgrho/phash/blob/ab46a05226961750a59003494c1a95a4ae8b0131/src/Shipwreck.Phash/ImagePhash.cs#L167-L196

from imagehash.

developervariety avatar developervariety commented on June 15, 2024

Thank you for looking into this @pgrho. Very much appreciated, I'll stick to what works for my project for now.

from imagehash.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.