GithubHelp home page GithubHelp logo

commonsmachinery / blockhash-js Goto Github PK

View Code? Open in Web Editor NEW
167.0 167.0 48.0 5.79 MB

Image perceptual hash calculation in javascript

Home Page: http://blockhash.io/

License: MIT License

JavaScript 95.63% Makefile 4.37%

blockhash-js's People

Contributors

artfwo avatar denisnazarov avatar jonasob avatar petli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blockhash-js's Issues

Java implementation of blockhash

I needed to use blockhash-core in my Android app. So, I followed your C and JS implementations, and implemented it in Java. I was wondering if you'd be interested in mentioning the repo on your website or maybe move repository to your org?

Here is the link to java implementation: https://github.com/bbhopesh/blockhash-java

blockhash-java-lib is the Java implementation without any Android dependencies. blockhash-android-lib is wrapper for Android.

Detect image type from arrayBuffer

blockhash-js should be able to detect the image type from the arrayBuffer directly, without having to resort to the content type of the xhr request. See:

http://stackoverflow.com/questions/8349693/how-to-check-if-a-byte-array-is-a-valid-image
http://stackoverflow.com/questions/25841460/how-to-recognise-the-arraybuffer-is-string-or-image
http://stackoverflow.com/questions/4550296/how-to-identify-contents-of-a-byte-is-a-jpeg

This would allow the library to support hashing from an arrayBuffer from an instance of the FileReader class without having to supply content type.

https://developer.mozilla.org/en-US/docs/Web/API/FileReader

Blockhash or perceptual hash?

which algorithimn is used here? Because by

https://content-blockchain.org/research/testing-different-image-hash-functions/

We have two TYPES OF ALG. --->

BLOCKHASH - PERCEPTUAL HASH

ok, the name of this repo is blockhash-js, which one may think it is a blockhash based alg. But in the description it says "This is a perceptual image hash", which one may think it is a perceptual hash. (Of course, all both are for perception diff.)

But which of these two is the alg. used here? (Need some clarification on docs, because i got confused)

Local Image Files?

I get an "Error: Couldn't decode image" message when I attempt to use blockhash on an image file stored locally on my computer, for example "C:\Users\Bob\Desktop\blockhash\image.jpg". I have no issue with files stored online, for example "http://example.com/image.jpg". Is it possible to use the Javascript version of blockhash on local files? Is there a step I'm missing to do this? Thanks!

blockhash-js module not registered with NPM

It seems like the command npm install blockhash-js doesnt work. Apparently iit is not yet registered with the npm registry. Is it really registered yet or in due process?

"Flipping" hash?

I want to get two hashes for an image -- one for the original and one in which the image is mirrored across the Y axis (mirror image).

I tried creating another result array with values in blocks reversed here but somehow am ending up with the same output from translate_blocks_to_bits so im afraid I'm missing something obvious.

Any hints on how I could accomplish this?

png-js not found

dependence png-js doesnt exist. even after sudo npm install png-js and it existing on my node_modules or yarn add... Why?

Incorrect hashing of png

This image: https://commons.wikimedia.org/wiki/File:Arius.png

It's getting incorrectly hashed by blockhash-js, which gives a hash of 00ec008bbe80ffbf0000e9f9f8fb80fdffffffffffffffffffffffffffffffff instead of 0ff91ff10ff1000300018fd984d79ddf8e058fc30fc30fc3dfc3c3c303831783 as would be expected (from the C blockhash). The trailing fffff is a tell tale sign of an issue, which look very similar to the issue we had with jpeg where jpeg-js made assumptions about the image being RGB. Could something similar be amiss here?

one_bits variable

I was wondering if anyone could shed light on the one_bits array since I do not have access to the original paper upon which this library is based.

I can see that the hammingDistance function essentially calculates the bit difference between the relevant char in the two hashes to be compared. this XOR operation n1^n2 will, in theory, be in the range 0 to 15, since parseInt("0",16)=0 and parseInt("f",16)=15.
So my question is that the one_bits array seems to essentially "decelerate" the hamming distance by increasing the distance by either 0,1,2,3, or 4 instead of the bit difference (0-15). Why does the algorithm do this?
var one_bits = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4];
Interestingly, the one_bits array is non-linear, so a bit difference of 3 will increase distance by 2 whereas a bit difference of 4 will increase distance by 1...??

Thanks!

Incorrect calculation of median

median([1,2,3,4]) should return 2.5, but the current implementation mistakenly returns 3.5 due to a bug in index calculation:

var median = function(data) {
    var mdarr = data.slice(0);
    mdarr.sort(function(a, b) { return a-b; });
    if (mdarr.length % 2 === 0) {
        return (mdarr[mdarr.length/2] + mdarr[mdarr.length/2 + 1]) / 2.0;
    }
    return mdarr[Math.floor(mdarr.length/2)];
};

should be

var median = function(data) {
    var mdarr = data.slice(0);
    mdarr.sort(function(a, b) { return a-b; });
    if (mdarr.length % 2 === 0) {
        return (mdarr[mdarr.length/2 - 1] + mdarr[mdarr.length/2]) / 2.0;
    }
    return mdarr[Math.floor(mdarr.length/2)];
};

How to decide/determine # of bits?

Im not familiar w/ image or file handling, so the language about the bits param in the docs is unclear to me. Can someone elaborate on what is meant by "number of bits in a row"?

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.