Skip to content

modules/img_hash/src/marr_hildreth_hash.cpp: error in kernel computation ? #3940

Open
@orzel

Description

@orzel

In modules/img_hash/src/marr_hildreth_hash.cpp:getMHKernel(), the line reads

kPtr[col] = (2-a)*std::exp(a/2);

While it seems it should be

kPtr[col] = (2-a)*std::exp(-a/2);

At least that's what the original code does: https://github.com/aetilius/pHash/blob/master/src/pHash.cpp#L610

CImg<float> *GetMHKernel(float alpha, float level) {
    int sigma = (int)4 * pow((float)alpha, (float)level);
    static CImg<float> *pkernel = NULL;
    float xpos, ypos, A;
    if (!pkernel) {
        pkernel = new CImg<float>(2 * sigma + 1, 2 * sigma + 1, 1, 1, 0);
        cimg_forXY(*pkernel, X, Y) {
            xpos = pow(alpha, -level) * (X - sigma);
            ypos = pow(alpha, -level) * (Y - sigma);
            A = xpos * xpos + ypos * ypos;
            pkernel->atXY(X, Y) = (2 - A) * exp(-A / 2);
        }
    }
    return pkernel;
}

And that also matches the formula given on wikipedia: https://en.wikipedia.org/wiki/Ricker_wavelet

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions