Introduction
As indicated by IDC, digital information will skyrocket up to 175 zettabytes, and the vast part of this information will be reflected. Data scientists must (pre) medir estas imágenes antes de convertirlas en modelos de inteligencia artificial y deep learningDeep learning, A subdiscipline of artificial intelligence, relies on artificial neural networks to analyze and process large volumes of data. This technique allows machines to learn patterns and perform complex tasks, such as speech recognition and computer vision. Its ability to continuously improve as more data is provided to it makes it a key tool in various industries, from health.... They need to do the important work (and sometimes dirty) before the nice part begins.
To handle a large amount of information with efficiency and speed without negotiating the results, data scientists need to use image preparation instruments for artificial intelligence and deep learning tasks.
In this article, I will dive into the most useful image processing libraries in Python that are used vigorously in artificial intelligence and deep learning tasks. Then let's get started!
Table of Contents
- OpenCV
- Scikit Image
- Scipy
- Python Image Library (Pillow / PIL)
- Matplotlib
- SimpleITK
- Numpy
- Mahotas
OpenCV
OpenCV is one of the most famous and used open source libraries for computer vision tasks such as image processing, object detection, face detection, segmentationSegmentation is a key marketing technique that involves dividing a broad market into smaller, more homogeneous groups. This practice allows companies to adapt their strategies and messages to the specific characteristics of each segment, thus improving the effectiveness of your campaigns. Targeting can be based on demographic criteria, psychographic, geographic or behavioral, facilitating more relevant and personalized communication with the target audience.... of images, face recognition, and many more. Apart of this, can also be used for machine learning tasks. This was developed by Intel in 2002. It is written in C ++ but the developers have provided python and java bindings. It is easy to read and use.
To create machine learning and computer vision models, OpenCV has more than 2500+ algorithms. These algorithms are very useful for performing various tasks such as facial recognition., object detection and many more. Let's see some examples where we can perform using OpenCV:
Grayscale
Grayscale is a method of converting an image of 3 channels, for instance, RGB, HSV, etc., in a single-channel image, namely, in shades of gray. The final image varies between full black and white. The importance of grayscale includes the reduction of dimensions (convert 3 channels in a single-channel image), reduce model complexity, etc.
Below the code, the fragment shows the grayscale in OpenCV
import cv2 as cv img = cv.imread('example.jpg') cv.imshow('Original', img) cv.waitKey() #Use cvtColor, to convert to grayscale gray_img = cv.cvtColor(img, cv.COLOR_BGR2GRAY) cv.imshow('Grayscale', gray_img) cv.waitKey(0)
Rotate image
OpenCV helps to rotate the image in any range of degrees of 0 a 360 degrees.
Check the following code to rotate the image 180 degrees.
import cv2 as cv
import matplotlib.pyplot as plt
img = cv.imread('example.jpg')
h, w = image.shape[:2]
rot_matrix = cv.getRotationMatrix2D((w/2.h/2), -180, 0.5)
rot_image = cv.warpAffine(img, rot_matrix, (w, h))
plt.imshow(cv.cvtColor(rot_image, cv.COLOR_BGR2RGB))
OpenCV provides other functionalities in addition to those we have discussed so far. Apart of this, also helps in face detection, image segmentation, feature extraction, object detection, 3-D reconstruction and many more.
For more information, consult the official documentation: Link
Scikit Image
Scikit-Image is another great open source image processing library. Useful in almost any machine vision task.. It is one of the simplest and simplest libraries. Some parts of this library are written in Cython (is a superset of Python programming language designed to make Python faster as C language). Provides a large number of algorithms including segmentation, color space manipulation, geometric transformation, filtered out, morphology, feature detection and many more.
Scikit Image uses Numpy arrays as image objects. Let's see how we can perform an active contour operation on the scikit image. Active outline describes the boundaries of shapes in an image.
Check the following code for the active contour feature:
import numpy as np import matplotlib.pyplot as plt from skimage.color import rgb2gray from skimage import data from skimage.filters import gaussian from skimage.segmentation import active_contour image = data.astronaut() # Data for circular boundary s = np.linspace(0, 2*np.pi, 400) x = 220 + 100*np.cos(s) y = 100 + 100*np.sin(s) init = np.array([x, Y]).T # formation of the active contour centre = active_contour(Gaussian(image, 3),init, alpha=0.015, beta=10, gamma=0.001) figure, axis = plt.subplots(1, 2, figsize=(7, 7)) Ax[0].imshow(image, cmap=plt.cm.gray) Ax[0].set_title("Original Image") Ax[1].imshow(image, cmap=plt.cm.gray)
For more information, consult the official documentation: Link
Science
SciPy is mainly used for mathematical and scientific calculations, but sometimes it can also be used for basic image manipulation and processing tasks using the submodule scipy.ndimageAt the end of the day, images are only multidimensional arrays, SciPy provides a set of functions that are used to operate n-dimensional Numpy operations. SciPy provides some basic image processing operations, as face detection, convolution, image segmentation, reading images, feature extraction, and many more. along with this, also performs filtering, draw outline lines on images.
Check the following code to blur an image with SciPy:
from scipy import ndimage, misc
from matplotlib import pyplot as plt
f = misc.face()
b_face = ndimage.gaussian_filter(f, sigma=3)
figure, axis = plt.subplots(1, 2, figsize=(16, 8))
For more information, consult the official documentation: Link
Python Image Library (PIL / Pillow)
It is an open source Python library that is used for image processing tasks. Provides special functionality that is usually not provided by other libraries. how to filter, open, manipulate and save images. This library supports a wide range of file formats, what makes it more efficient. PIL also supports functions such as image processing, viewing images and image files. Let's see Image enhancement using PIL / Pillow.
Change the sharpness of an image:
For more information, consult the official documentation: Link
Matplotlib
Matplotlib is mainly used for 2D visualizations like scatterplots, bar graphs, histogramasHistograms are graphical representations that show the distribution of a dataset. They are constructed by dividing the range of values into intervals, O "Bins", and counting how much data falls in each interval. This visualization allows you to identify patterns, trends and variability of data effectively, facilitating statistical analysis and informed decision-making in various disciplines.... and many more, but we can also use it for image processing. IIt is effective for obtaining information from an image.. It does not support all file formats.
Check the following image after the background color change operation:
For more information, consult the official documentation: Link
SimpleITK
It is also called Knowledge Segmentation and Registration Toolkit. It is an open source library used for image registration and image segmentation. Libraries like OpenCV consider the image as an array, but this library considers the images as a set of points in a region in space. Check the following example:
Image Segmentation
For more information, consult the official documentation: Link
Numpy
It is an open source Python library used for numerical analysis. Contains an array and multidimensional arrays as data structures. But NumPy can also use for image processing tasks such as image cropping, pixel manipulation and pixel value masking.
Check the following picture to extract the green channels / Red / picture blue:
For more information, consult the official documentation: Link
Mahotas
It is another open source Python library for computer vision and image processing.. It was designed for biometric computing. Provides many algorithms that are written in C ++ for speed with a good python interface. Read and write images in NumPy arrays.
Check the following image for template matching using Mahotas:
For more information, consult the official documentation: Link
Conclution
Then, in this article, we have covered the 8 Top Python Image Processing Libraries for Machine Learning in 2021. Hope you learn something from this blog and it turns out better for your project. Thanks for reading and your patience. Good luck!
You can check my articles here: Articles
Thank you for reading this article on Python libraries for image processing and for your patience.. Leave me in the comment section. Share this article, it will give me the motivation to write more blogs for the data science community.
Email identification: gakshay1210@ gmail.com
Follow me on LinkedIn: LinkedIn
The media shown in this article is not the property of DataPeaker and is used at the author's discretion.