Image Processing using Mahotas and Python
In this article, we will walk in through the image processing using Mahotas and Python.
Image processing :
Image processing is the method through which we can do a certain operation on image to enhance and to extract some useful knowledge from the image. Here the input is in the form of image and output is in the form of an image or some feature or characteristic of the image. It is nowadays one of the rapidly growing technology. It gives the platform for the research area. They are two types of image processing analog and digital. Analog image processing can be used for hard copies like print out. Digital image processing techniques help in the manipulation of the digital image by using a computer.
Mahotas is one of the computer vision and image processing library for python. A library is a set of function and method that allows us to perform many actions. It has around 100 functions for image processing. It contains many algorithms that are operated in an array and with a very clean Python interface. The algorithm of Mahotas is coded in c++ programming language. The interface of it is in python which helps for fast development and algorithm are codded in c++ which are tuned for speed. Some of the Mahotas functions are color space conversion, convolution, convex points calculations, hit, and miss. thinning, morphological processing, Sobel edge detection, Speeded-Up Robust Features (SURF), a form of local features, thresholding, watershed, Zernike & Haralick, local binary patterns, and TAS features.
To go with the Mahotas and python for image processing we need to first install the library of the Mahotas for this the code is
Pip install mahotas
In conda prompt.
Once we have installed the Mahotas we need to import Mahotas and import imshow from Pylab, for display and performing a certain operation on the image.
import mahotas as mh from pylab import imshow, show
here we have imported the mahotas as mh.
We have completed the part of importing library which we need for image processing. Next we are going to perform certain operation on image.
loading image and converting image into an array of RGB values we nee to write the following code.
#loading image and converting image into an array of RGB values im = mh.imread('myheroacademia_vol_25.jpg') im
>array([[[148, 55, 144], [148, 55, 144], [148, 55, 144], ..., [146, 56, 143], [135, 50, 133], [225, 142, 222]], [[148, 55, 144], [148, 55, 144], [148, 55, 144], ..., [146, 56, 143], [135, 50, 133], [225, 142, 222]], [[148, 55, 144], [148, 55, 144], [148, 55, 144], ..., [146, 56, 143], [135, 50, 133], [225, 142, 222]], ..., [[143, 56, 151], [148, 54, 150], [152, 52, 148], ..., [ 8, 4, 3], [ 4, 5, 7], [ 69, 86, 96]], [[145, 55, 153], [148, 54, 151], [152, 52, 150], ..., [ 8, 4, 3], [ 4, 5, 7], [ 69, 86, 96]], [[145, 55, 155], [149, 53, 153], [152, 52, 150], ..., [ 8, 4, 3], [ 4, 5, 7], [ 69, 86, 96]]], dtype=uint8)
We can call the shape of the image by this we will know the width height and colour channel :
# This will display the width, height and how many color channels the image has im.shape
>>(1800, 753, 3)
An rgb image always represented as 3 dimensional array shape that is (heigtht ,width ,3 )
We can see the image in full size by the function imshow()
Next we will see how we can transpose the RGB values from image .this will help to assign value to image converted array into green ,blue , and red values .
r,g,b = im.transpose((2,0,1))
we wiil now see the mahotas function to change the image from RGB to sepia.
tomura_sepia = mh.colors.rgb2sepia(im) imshow(tomura_sepia)
we can also use the gamma correction on image to raise the intensity of light of RGB value by this we will get the proper image.
# Changing the gamma values to the second power imshow(im ** 2.0) >>
Here we have to change the gamma values to a second power
In this, we have manipulated the image using Mahotas and Python.