Ask Your Question
4

Image hashing implantation?

asked 2012-11-14 17:00:20 -0600

Cory gravatar image

updated 2012-11-21 01:54:48 -0600

SR gravatar image

I know it is loaded question but what is the best way to hash a image so that similar images can be identified. Is there any implantation? I am looking for something that can detect minor modification to an image

One of the paper I found is: http://research.microsoft.com/pubs/77279/venkie00robust.pdf

[edit]

Maybe hashing is not a good word to use when trying to identify similar images. I want to be able to match two images with minor changes such as: resize, crop, texted added on image etc.

I want to generate string or number based of an image. Using the generated string or number, I want to compare how similar the images are.

Example:

temp.jpg  generates "abcdef123456789"
temp-crop.jpg generates  "abcdef12345678a"

Based on the generated strings, I can calculate how similar the images are. Maybe using Hamming Distance. Few differences in the string, it indicates minor changes in the images

edit retag flag offensive close merge delete

Comments

You need to say if you want to find/detect identical images (=duplicates) or similar images (=near duplicates). This makes a big difference.

SR gravatar imageSR ( 2012-11-15 02:00:00 -0600 )edit

3 answers

Sort by ยป oldest newest most voted
4

answered 2012-11-15 00:55:27 -0600

Michael Burdinov gravatar image

updated 2012-11-16 06:01:34 -0600

Using hash for detecting similar images is not a very popular approach. Actually the paper you mentioned really surprised me, because normally hash functions can't be used for estimation of image similarity. Are you searching specifically for hashing, or anything that allows you to compare images is good? There many ways to find similar images based on comparison of color histograms. Or if your tasks is simple enough maybe even comparing average intensities will do the trick.

Edit:

You can start from this tutorial.

edit flag offensive delete link more

Comments

See [edit]

Cory gravatar imageCory ( 2012-11-15 11:36:39 -0600 )edit

See my edit

Michael Burdinov gravatar imageMichael Burdinov ( 2012-11-16 06:03:16 -0600 )edit
3

answered 2016-07-02 21:46:14 -0600

stereomatching gravatar image

updated 2016-07-03 02:05:29 -0600

I have the same problem as Cory recently, to solve this problem once and for all, I develop an img_hash module for open_contrib, here is the pull request. img_hash module port the image hash algorithms of PHash library and implement some algorithms do not exist in the PHash library, this include color moment hash which provide good resistance to rotation attack(-90 to 90 degree).

The ReadMe of img_hash module should give you enough information of how to use and install the module, if you need more info, please ask me from the forum, or send the question to my [email protected]

This module is very easy to use, unlike PHash library, the api are consistent and do not force you to handle the resource by yourself.

#include <opencv2/core.hpp>
#include <opencv2/core/ocl.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/img_hash.hpp>
#include <opencv2/imgproc.hpp>

void computeHash(cv::Ptr<cv::img_hash::ImgHashBase> algo)
{
    cv::Mat const input = cv::imread("lena.png");
    cv::Mat const target = cv::imread("lena_blur.png");

    cv::Mat inHash; //hash of input image
    cv::Mat targetHash; //hash of target image

    //comupte hash of input and target
    algo->compute(input, inHash);
    algo->compute(target, targetHash);
    //Compare the similarity of inHash and targetHash
    //recommended thresholds are written in the header files
    //of every classes
    double const mismatch = algo->compare(inHash, targetHash);
    std::cout<<mismatch<<std::endl;
}

int main()
{
    //disable opencl acceleration may(or may not) boost up speed of img_hash
    cv::ocl::setUseOpenCL(false);

    computeHash(img_hash::AverageHash::create());
    computeHash(img_hash::PHash::create());
    computeHash(img_hash::MarrHildrethHash::create());
    computeHash(img_hash::RadialVarianceHash::create());
    //BlockMeanHash support mode 0 and mode 1, they associate to
    //mode 1 and mode 2 of PHash library
    computeHash(img_hash::BlockMeanHash::create(0));
    computeHash(img_hash::BlockMeanHash::create(1));
    computeHash(img_hash::ColorMomentHash::create());
}

You can measure the performance of the algorithms under different by this graph and pick the one suit by your needs.

image description

ps : At first I give BOVW a shot, the results are solid, but it take too many times to build the coed book and retrieve the features from image. Then I found image hash can help me boost up the speed(although it do not provide best accuracy).

edit flag offensive delete link more
1

answered 2012-11-16 03:08:51 -0600

SR gravatar image

updated 2012-11-16 05:14:04 -0600

You should have a look at this paper:
Scalable near identical image and shot detection
O. Chum, J. Philbin, M. Isard, A. Zisserman, CIVR 2007

It uses locality-sensitive hashing and min-hashing to index/find near-duplicates in image databases. But beware: these hashing methods are essentially a nearest-neighbour search and not comparable to traditional hashing at all!

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-11-14 17:00:20 -0600

Seen: 5,766 times

Last updated: Jul 03 '16