In our world there’s a lots of data and images. These images need to be processed.
Common tasks in image processing include displaying images, basic manipulations like cropping, flipping, rotating etc.
Classification and feature extractions, Image restoration and Image recognition.
All these things we can do with python .Python is the best choice for all these tasks.
It has many image processing tools. You can use any one of these.
Most image processing and manipulation techniques can be carried out effectively using two libraries: Python Imaging Library (PIL) and Open Source Computer Vision (OpenCV).
But other libraries are also have good features. Some of them are:
Numpy is one of the core libraries in Python programming and provides support for arrays. An image is essentially a standard Numpy array containing pixels of data points. The image can be loaded using skimage and displayed using matplotlib.
Using Numpy to mask an image:
import numpy as np from skimage import data import matplotlib.pyplot as plt %matplotlib inline image = data.camera() type(image) numpy.ndarray #Image is a numpy array mask = image < 87 image[mask]=255 plt.imshow(image, cmap='gray')
Scipy is another of Python’s core scientific modules like Numpy and can be used for basic image manipulation and processing tasks. In particular, the submodule (scipy.ndimage) provides functions operating on n-dimensional Numpy arrays. The package currently includes functions for linear and non-linear filtering, binary morphology, B-spline interpolation, and object measurements.
from scipy import misc,ndimageface = misc.face() blurred_face = ndimage.gaussian_filter(face, sigma=3) very_blurred = ndimage.gaussian_filter(face, sigma=5) #Results plt.imshow(<image to be displayed>)
PIL( Python Imaging Library) is a free library for the Python programming language that adds support for opening, manipulating, and saving many different image file formats. However, its development has stagnated, with its last release in 2009. Fortunately, there is Pillow, an actively-developed fork of PIL which is easier to install; runs on all major operating systems and supports Python 3. The library contains basic image processing functionality, including point operations, filtering with a set of built-in convolution kernels, and colour space conversions.
from PIL import Image, ImageFilter #Read image im = Image.open( 'city.jpg' ) #Display image im.show() from PIL import ImageEnhance enh = ImageEnhance.Contrast(im) enh.enhance(1.8).show("30% more contrast")
OpenCV (Open Source Computer Vision Library) is one of the most widely used libraries for computer vision applications. OpenCV-Python is the python API for OpenCV. OpenCV-Python is not only fast since the background consists of code written in C/C++ but is also easy to code and deploy(due to the Python wrapper in foreground). This makes it a great choice to perform computationally intensive computer vision programs.
Here is an example which shows the capabilities of OpenCV-Python in Image Blending using Pyramids to create a new fruit called ‘Orapple’.
Pycairo is a set of python bindings for the graphics library cario Cairo is a 2D graphics library for drawing vector graphics. Vector graphics are interesting because they don’t lose clarity when resized or transformed. Pycairo is a set of bindings for cairo which can be used to call cairo commands from Python.
These are some of the useful and freely available Image Processing libraries in Python.
And there are many more.Some are fairly known and some may be new for you.