Calculate image intensities, a database friendly alternative to image hashing..
Project description
image_intensities
Python implementation of the great derpibooru/image_intensities.
The algorithmic overview is to convert the image into the yuv colorspace, drop the u and v components, and then average the y component over 4 evenly-spaced rectangles on the image dimensions.
Usage
from image_intensities import png_intensities, jpeg_intensities
luma = png_intensities('/absolute/path/to/954482.png') # image can ge found in the tests folder.
luma = jpeg_intensities('/absolute/path/to/2544057.jpg') # image can ge found in the tests folder.
# returns something like
luma == Luma(nw=0.42, ne=0.44, sw=0.58, se=0.69)
from image_intensities import rgb_luma_from_filename, Luma
luma = rgb_luma_from_filename('/path/to/image.png')
# returns something like
luma == Luma(nw=0.42, ne=0.44, sw=0.58, se=0.69)
Dependencies
C-Extension
libpng
- MacOS:
brew install libpng
(tested to work with 1.6.37) - Ubuntu:
sudo apt-get update && sudo apt-get install libpng-dev
- Dockerfile, Ubuntu based:
apt-get update -y && apt-get install -y libpng-dev && apt-get clean && rm -rfv /var/lib/apt/lists/*
-
⚠️ Make sure you pull a recent release of the python docker image (even if it's an older python version!). Especially if you're getting errors complaining about a
png_set_longjmp_fn
function when you try to use it. As time of writing the 2-month old version did not work, but the newest releases (python:3.6
:6ac87e65b6d0
,pythong:3.9
:1b33974176a3
) ones have that fixed.
-
Installation
See dependencies above, and make sure those are installed.
Install via pip
pip install image_intensities
Mac OS:
CPPFLAGS='-I/usr/local/include/' LDFLAGS='-L/usr/local/lib/' pip install image_intensities
From source
E.g. you checked out this repository:
python setup.py install
Mac OS:
CPPFLAGS='-I/usr/local/include/' LDFLAGS='-L/usr/local/lib/' python setup.py install
Minimal installation example
Using docker as it already has a working libpng-dev
:
docker pull python:3.9
docker run -it --rm python:3.9 bash
pip install image_intensities
# test import
python -c"import image_intensities as it; print(it._intensities.ffi)"
# test with a png
wget https://derpicdn.net/img/download/2015/8/9/954482.png -O /tmp/954482.png
python -c"from image_intensities import png_intensities; print(png_intensities('/tmp/954482.png'))"
# test with a jpg
wget https://derpicdn.net/img/download/2021/2/4/2544057.jpg -O /tmp/2544057.jpg # we need to use an absolute path!
python -c"from image_intensities import jpeg_intensities; print(jpeg_intensities('/tmp/2544057.jpg'))"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for image_intensities-0.0.10.dev3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72b46b81c8920276990ccdcd7cd8afdb8d233b8734fb15e1360060b1d3d0242d |
|
MD5 | 83cb04798f101fe84cf868b77bd6b7c1 |
|
BLAKE2b-256 | c2f516e3bca303a00db4c3b13859028a59962fb159a70d52552f0e0b0ddff878 |