Git Product home page Git Product logo

dhash's Introduction

I'm Ben Hoyt, an experienced software developer from Christchurch, New Zealand. I'm also a unicyclist and love spoonerisms (ask me about Prinderella and the Cince).

I love writing readable Go and Python code, and I'm currently working on GoAWK, my AWK interpreter with CSV support (written in Go). I also do a fair bit of technical writing over on my website.

I dabble in other open source projects, with small submissions to the Go programming language, and a minor but heavily-used addition to Python a number of years ago -- the os.scandir() function, which sped up os.walk() by 2-10x.

If you use my projects or enjoy my writing, I'd love for you to sponsor me to help my personal projects stay well-maintained and to keep me motivated! Even a coffee's worth is a nice perk. Thanks! :-)

dhash's People

Contributors

benhoyt avatar elliotwutingfeng avatar smason 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  avatar  avatar  avatar  avatar

dhash's Issues

Get CI tests working again, particularly macOS

These have stopped working, as you can see from this run. On both Windows and macOS it looks like 2.7 is no longer supported (maybe we should just remove the tests on 2.7). But all the macOS tests seem to be failing, seemingly due to ImageMagick not being installed on the latest macos runners. This can probably be fixed with a brew install imagemagick.

can't get correct dhash from a icon picture

testpictures.zip

I attached the picture in the zip file, one is icon type, and the other is png type
dhash of the icon type returns a value of 0
dhash of the icon type returns a value of 62738665417926919091179733734494077055

I tried both 1.4 and 1.3 dhash version. Also tried both PIL and wand

do you have any comment about this? Do I need to covert icon picture to png first to get a meaningful value? Thanks

Optimize dHash

Hello I use your code since a bit while and I find it pretty awesome and useful, I'm using either to detect copies and also for a project to regenerate a picture as a mozaic of other pictures, first I was using dHash and PIL, then use the basic deltaE with Lab channels to compare overall color difference of two images and went to use OpenCV for lesser and faster comparison. And then I facepalm myself, thinking ...

Maybe it'd be a good idea to do dHash on each Lab channels but I'm not sure how to do it right, the L is the BW equivalent which values goes from 0 to 100 of dHash and a&b are two orthogonal (independant) chroma with a going from -128 to 127 -> green to red and b -128 to 127, thankfully openCV already normalize each value from 0 to 100 after conversion from RGB.

So I'd like to have your opinion

  • Is Luminance is as important as color (or twice) ?
  • Should we compute two separate matrix difference, one for luminance and one for colour ?
  • What about to port this algorithm to opencv ? (I've started to work on it)

handling of transparancy

I've just been playing with your library and it kept telling me that images were very different when they looked the same. It seems that it was due to the color present in transparent areas.

For example; if I create two images as:

from PIL import Image, ImageDraw

# greyscale image, completely white and also completely transparent
im1 = Image.new('LA', (100, 100), (0xff, 0))

im2 = im1.copy()
# replace most of it with "transparent black"
ImageDraw.Draw(im2).rectangle((10, 10, 90, 90), (0, 0))

and then run dhash on them:

from dhash import dhash_row_col
print(dhash_row_col(im1), dhash_row_col(im2))

I get very different results, even though they'll be rendered the same as far as most viewers are concerned. They're obviously "different" images and you can use an image editor to pull the channels apart and show this. But given that this library is about perceptual differences I think it should probably do something about this.

I'm working around this by filling transparent areas with white, as suggested in:

python-pillow/Pillow#2609 (comment)

def fill_transparent(image, fill_color='white'):
  if image.mode in ('RGBA', 'LA'):
    cleaned = Image.new(image.mode[:-1], image.size, fill_color)
    cleaned.paste(image, image.split()[-1])
    return cleaned
  return image

print(*[dhash_row_col(fill_transparent(im)) for im in [im1, im2]])

Not sure if this is deliberate, or if/how it should be exposed to users of the library โ€” hence opening an issue rather than pull request.

get_num_bits_different() is ambiguous

The function compares two INT hashes, not any hash the library calculates. I think it is very unintuitive. At least the function have to either convert the inputs to be right, or provide an explanation on what it expects.

Deprecation warning with regards to pillow

I noticed this while running tests on a project of mine and thought I'd bring it up:

  /long/path/dhash.py:66: DeprecationWarning: ANTIALIAS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead.
    small_image = gray_image.resize((width, height), PIL.Image.ANTIALIAS)

Referring to the resize operation here:

    elif PIL is not None and isinstance(image, PIL.Image.Image):
        gray_image = image.convert('L')
        small_image = gray_image.resize((width, height), PIL.Image.ANTIALIAS)
        return list(small_image.getdata())

This was found while using pillow==9.2.0 and dhash==1.3

Cheers!

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.