Git Product home page Git Product logo

Comments (9)

oliver-moran avatar oliver-moran commented on July 19, 2024

This is the same issues as with Taylor in #66. Use the latest version of phash.js straight from GitHub. Just copy and paste it over the one in your node_modules directory. When you do that it will work:

Hillary:            cAjc7i6AH1r
Hillary (scribble): e0kL7a0k9hi

Distance:   0.3125
Diff:       0.2898695136417556

I'll release it tonight. Sit tight.

from jimp.

marcolino avatar marcolino commented on July 19, 2024

Thanks... Just testing...

I plan to use distance (because it's a value can be pre-calculated and saved to DB, and to check for image duplication I just need a hamming distance, for every DB image).

To use diff() I should call it once for each DB image, right? I'm afraid it should be too slow (db is expected to reach ~750K images...). Correct me if wrong, please...

One more thing, about hashes lengths: you said it is due to chance... But so I can't expect hashes lengths to be all the same? But if they do differ, how do I calculate a distance???
Thanks for your attention!

from jimp.

marcolino avatar marcolino commented on July 19, 2024

While calculating hashes for my images, I get:

my-app/node_modules/jpeg-js/lib/decoder.js:323
        throw "marker was not found";
        ^
 marker was not found
[21:20:35] [nodemon] app crashed - waiting for file changes before starting...

and my app crashes... Probably the image was empty, but Jimp should try to catch these errors, to avoid crashing, right? I (Jimp user) could catch these exceptions, too, but...

from jimp.

oliver-moran avatar oliver-moran commented on July 19, 2024

I think your strategy regarding distance and diffing sounds good.

About exceptions: Errors in Jimp are handled by throwing exceptions (unless a Node-style callback is passed). Yes, that will crash your app but I'm delegating that to you to catch. Most are a straight-forward case of a wrong argument being passed to a method so I'm surprised at the error you got.

To compute the hammering distance, you would be better off converting the base 64 hash to binary and padding to 64 digits with leading zeros as necessary. You can get the binary quite easily with: image.hash(2); Compute the hammering distance against those.

I'm planning on padding each the hashes with leading 0s as necessary for this reason.

from jimp.

oliver-moran avatar oliver-moran commented on July 19, 2024

I've also just made a fix where hashes will be returned with leading zeros. This will make it easier to compare binary hashes stored in a DB for hammering distance.

from jimp.

marcolino avatar marcolino commented on July 19, 2024

This night I did realize why 11... :-)
Correct me if wrong: to encode a byte in base64 you need 6 bits (2^6 = 64). Then to encode 64 bits you need 11 base64 bytes (64 / 6 = 10.6...) (i.e.: you need 10 full base64 bytes, plus one, that you'll use for the last 4 bits... Hence, no need for padding, it's automatic...
Please don't tell me I'm completely wrong... :-D

from jimp.

oliver-moran avatar oliver-moran commented on July 19, 2024

The padding is in case the first bit is not 1:

var white = new Jimp(256, 256, 0xFFFFFFFF);
var black = new Jimp(256, 256, 0x000000FF);

console.log("W: " + white.hash(2));
console.log("B: " + black.hash(2));

// Output:
// W: 1000000000000000000000000000000000000000000000000000000000000000
// B: 0000000000000000000000000000000000000000000000000000000000000000

console.log("W: " + white.hash(64));
console.log("B: " + black.hash(64));

// Output:
// W: 80000000000
// B: 00000000000

from jimp.

marcolino avatar marcolino commented on July 19, 2024

Perfect...

Marco Solari
System Analyst, Software Engineer and IT Consultant at Koinè Sistemi Torino

On 10 November 2015 at 10:28, Oliver Moran [email protected] wrote:

The padding is in case is if the first bit is not 1:

var white = new Jimp(256, 256, 0xFFFFFFFF);
var black = new Jimp(256, 256, 0x000000FF);

console.log("W: " + white.hash(2));
console.log("B: " + black.hash(2));

// Output:
// W: 1000000000000000000000000000000000000000000000000000000000000000
// B: 0000000000000000000000000000000000000000000000000000000000000000

console.log("W: " + white.hash(64));
console.log("B: " + black.hash(64));

// Output:
// W: 80000000000
// B: 00000000000


Reply to this email directly or view it on GitHub
#67 (comment).

from jimp.

marcolino avatar marcolino commented on July 19, 2024

Already in NPM ?

Marco Solari
System Analyst, Software Engineer and IT Consultant at Koinè Sistemi Torino

On 10 November 2015 at 10:33, Marco Solari [email protected] wrote:

Perfect...

Marco Solari
System Analyst, Software Engineer and IT Consultant at Koinè Sistemi Torino

On 10 November 2015 at 10:28, Oliver Moran [email protected]
wrote:

The padding is in case is if the first bit is not 1:

var white = new Jimp(256, 256, 0xFFFFFFFF);
var black = new Jimp(256, 256, 0x000000FF);

console.log("W: " + white.hash(2));
console.log("B: " + black.hash(2));

// Output:
// W: 1000000000000000000000000000000000000000000000000000000000000000
// B: 0000000000000000000000000000000000000000000000000000000000000000

console.log("W: " + white.hash(64));
console.log("B: " + black.hash(64));

// Output:
// W: 80000000000
// B: 00000000000


Reply to this email directly or view it on GitHub
#67 (comment).

from jimp.

Related Issues (20)

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.