importing python modules - ImageChops - python

I'm looking for a good way to analyze image similarity, using python.
I'm NOT looking for a way to establish whether two images are identical. I'm just looking for a way to establish the similarity between two images (e.g., if two images are very similar they could be given a "grade" of 9/10; if they are completely unalike, they'll be given a very low index, such as 2/10).
From some reading that I've done, the module ImageChops has been suggested - however, I haven't been able to find a way to download it.
If anyone knows how to download it, or has a suggestion for other effective solutions, I'd greatly appreciate their advice!
Thanks in advance!

ImageChops is a module from PIL(Pillow). To use the ImageChops function you need to pip install Pillow OR easy_install Pillow OR download the src & extract the src then from CMD CD to the extracted folder & run python setup.py install.
To use the ImageChops you can do this from PIL import ImageChops
you can read the document section
some basic usage example http://effbot.org/imagingbook/imagechops.htm
To check the difference between 2 images:
import Image
from PIL import ImageChops
im1 = Image.open("splash.png")
im2 = Image.open("splash2.png")
diff = ImageChops.difference(im2, im1)
there's a compare images script, but its not a PIL; its on scipy module
You may also check this script here

ImageChops is an module belong to Python Image Library(PIL). Just note that there is no image similarity algorithm (except pixel-wise) built-in in ImageChops, instead, it is a tool you used to write your own algorithm. There is a greate article here:
How can I quantify difference between two images?
The ImageChops module contains a number of arithmetical image operations, called channel operations (“chops”). These can be used for various purposes, including special effects, image compositions, algorithmic painting, and more.
http://effbot.org/imagingbook/imagechops.htm
you can download the Python Image Library here.
http://www.pythonware.com/products/pil/
There are precompiled package for windows user too.
http://www.lfd.uci.edu/~gohlke/pythonlibs/

Related

Difference between convert Imagemagik utility and python PIL convert

I used the convert Imagemagik utility to create the grayscale jpg images. Need help in finding the equivalent utility in Python. I tried PIL but this create png images.
I thought of calling the "convert" utility through python. Is there any better solution than this.
I want to feed the images in tensorflow. The issue is I am using tensorflow 1.1.
Huh? This works fine and creates a grey JPEG:
from PIL import Image
image=Image.open('start.png')
grey=image.convert('L')
grey.save("result.jpg")

Difference between cv2, scipy.misc and skimage

What is the main difference between
cv2.imread / resize/ imwrite
scipy.misc.imread / imresize/ imsave
skimage.io.imread / skimage.transform.resize / skimage.io.imsave
and how to decide which one to use?
I know cv2 and skimage have different encoder, and cv2 use 'BGR' not 'RGB' in default. But sometimes a script might use them together, for example main.py, where it uses scipy.misc.imread, cv2.imresize and cv2.imwrite. I am wondering the reason to do so.
The scipy.misc module exists historically as a place to gather functions that do not fit easily into the other SciPy submodules. It is slated for deprecation and should not be used.
In the Python ecosystem, I'd recommend imageio for reading images (or matplotlib.pyplot.imread, if you already are using matplotlib).
Scikit-image provides a convenient wrapper around all of these I/O libraries as skimage.io (it should pick up whatever is installed on your system already). It also ensures that images are converted to the correct data type and range formats for use with other skimage functions (see http://scikit-image.org/docs/dev/user_guide/data_types.html).
cv2.imread et al. operate on OpenCV image objects and, as you've already observed, those images are typically stored in BGR memory layout. But for loading PNGs and JPGs, most of these libraries listed above all wrap the same underlying C libraries, perhaps with slightly different parameters for compression etc.
I'd recommend that you use whichever functions minimize the dependency footprint of your script / package.

Python - Best way to find similar images in a directory

Here is the effect I am trying to achieve - Imagine a user submits an image, then a python script to cycle through each JPEG/PNG for a similar image in the current working directory.
Close to how Google image search works (when you submit your image and it returns similar ones). Should I use PIL or OpenCV?
Preferably using Python3.4 by the way, but Python 2.7 is fine.
Wilson
I mean, why not use both? It's trivial to convert PIL images into OpenCV images and vice-versa, and both have niche functions that can make your life easier. Pair them up with sklearn and numpy, and you're cooking with gas.
I created the undouble library in Python which seems a match for your issue.
It uses Hash functions to detect (near-)identical images in for example a directory. It works using a multi-step process of pre-processing the images (grayscaling, normalizing, and scaling), computing the image hash, and the grouping of images based on a threshold value.

How can i transform Image1 to Image2 using matplotlib.pyplot or another library in python

How can i transform Image1 to Image2 using matplotlib.pyplot or another library in Python?
Image 1:
Image 2:
(This image turned out to be confidential,i removed it because i can't delete the post. Sorry for the inconvenience)
Any help is appreciated.
Have a look at the Python Imageing Library (which also has python bindings, by the way), especially the ImageFilter module.
But tools like ImageMagick or one of the built-in filters in Gimp might be more suitable for experimenting.
Is it the experimental data and already filtered from image 1 to image 2 by someone else? I wonder whether you have the point spread function along with the raw image 1?

Histogram Equalization

I am a beginner in Python. I want to make a small project on histogram equalisation. Basically I want to include changing contrast, color and crop option etc in my project. I am blank right now. Please suggest something. I am very keen to make this project but how to start?
Python's PIL module has methods for controlling contrast, color, and cropping.
You can use PythonMagick. It suports histogram equalization:
import PythonMagick
img = PythonMagick.Image("original.png")
img.equalize()
img.write("equalized.png")
PythonMagick is not very well documented itself, but its API directly corresponds to Magick++ API. Use Magick++ documentation for reference.
If PIL is enough for you, stick with PIL, it is better supported. I installed PythonMagick from the Ubuntu package, the project page does not open for me.

Categories