-
Notifications
You must be signed in to change notification settings - Fork 332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rudimentary ICC color profile support to colorhash #110
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,12 +38,17 @@ install: | |
- conda install --quiet --file conda-requirements.txt | ||
- pip install coveralls | ||
|
||
# Work around conda's Pillow package lacking ImageCms | ||
- conda uninstall pillow | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and then here prefix the two commands here with |
||
- pip install pillow | ||
|
||
# Summerise environment | ||
# --------------------- | ||
- conda list | ||
- conda info -a | ||
|
||
# Install and test imagehash | ||
# -------------------------- | ||
- python setup.py install | ||
|
||
script: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,10 +31,11 @@ | |
|
||
from __future__ import (absolute_import, division, print_function) | ||
|
||
from PIL import Image | ||
import numpy | ||
#import scipy.fftpack | ||
#import pywt | ||
#import scipy.fftpack | ||
from PIL import Image, ImageCms | ||
|
||
__version__ = "4.1.0" | ||
|
||
""" | ||
|
@@ -270,7 +271,7 @@ def dhash_vertical(image, hash_size=8): | |
return ImageHash(diff) | ||
|
||
|
||
def whash(image, hash_size = 8, image_scale = None, mode = 'haar', remove_max_haar_ll = True): | ||
def whash(image, hash_size=8, image_scale=None, mode='haar', remove_max_haar_ll=True): | ||
""" | ||
Wavelet Hash computation. | ||
|
||
|
@@ -320,7 +321,7 @@ def whash(image, hash_size = 8, image_scale = None, mode = 'haar', remove_max_ha | |
|
||
|
||
|
||
def colorhash(image, binbits=3): | ||
def colorhash(image, binbits=3, ignore_icc=False): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use a positive variable name here to avoid the double negative. For example: |
||
""" | ||
Color Hash computation. | ||
|
||
|
@@ -332,11 +333,23 @@ def colorhash(image, binbits=3): | |
* the next 6*binbits encode the fraction in 6 bins of saturation, for mildly saturated parts of the remaining image | ||
|
||
@binbits number of bits to use to encode each pixel fractions | ||
@ignore_icc use raw color values, ignoring embedded ICC profiles | ||
""" | ||
|
||
if not ignore_icc: | ||
image_profile = image.info.get("icc_profile") | ||
if image_profile: | ||
from io import BytesIO | ||
# standardize color space to sRGB and preserve relative | ||
# color values by using perceptual rendering intent | ||
srgb_profile = ImageCms.createProfile("sRGB") | ||
image_profile = ImageCms.ImageCmsProfile(BytesIO(image_profile)) | ||
ImageCms.profileToProfile(image, image_profile, srgb_profile, | ||
renderingIntent=ImageCms.INTENT_PERCEPTUAL, inPlace=True) | ||
|
||
# bin in hsv space: | ||
intensity = numpy.asarray(image.convert("L")).flatten() | ||
h, s, v = [numpy.asarray(v).flatten() for v in image.convert("HSV").split()] | ||
h, s, _ = [numpy.asarray(v).flatten() for v in image.convert("HSV").split()] | ||
# black bin | ||
mask_black = intensity < 256 // 8 | ||
frac_black = mask_black.mean() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in line 9 add: