To make it compatible with other libraries, we need to change the order of the channels. Then, a pixel’s value of 0 in any of the layers indicates that there is no color in that particular channel for that pixel.Ī helpful note: When using the OpenCV’s imread function, the image is loaded as BGR instead of RGB. As before, the intensity of the color is presented on a 0–255 scale. The additional dimension represents each of the 3 color channels. In comparison to the grayscale image, this time the image is stored as a 3D np.ndarray. In scikit-image, this is the default model for loading the images using imread: image_rgb = imread('crayons.jpg')īefore printing the images, let’s inspect the summary to understand the way the image is stored in Python. In short, it is an additive model, in which shades of red, green and blue (hence the name) are added together in various proportions to reproduce a broad spectrum of colors. That is because they were automatically divided by 255, which is a common preprocessing step for working with images. By looking at the min and max values, we can see that they are in the range. The image is stored as a 2D matrix, 1280 rows by 1920 columns (high-definition resolution). Running the code produces the following output: - Image Details: - Image dimensions: (1280, 1920) Channels: G : min=0.0123, max=1.0000 Next, we run the helper function to print the summary of the image. Alternatively, we could have loaded the image using the default settings of imread (which loads an RGB image - covered in the next section) and converted it to grayscale using the rgb2gray function. In the second step, we define a helper function for printing out a summary of information about the image - its shape and the range of values in each of the layers.Īs the original image is in color, we used as_gray=True to load it as a grayscale image. There are many alternative approaches, some of the libraries include matplotlib, numpy, OpenCV, Pillow, etc. We use scikit-image, which is a library from scikit-learn’s family that focuses on working with images. First, we import all the required libraries: import numpy as np from lor import rgb2lab, rgb2gray, lab2rgb from skimage.io import imread, imshow import matplotlib.pyplot as plt In this section, we set up the Python environment. That is why in this post I focus on explaining the basics of working with color images in Python, how they are represented and how to convert the images from one color representation to another. And in the end, the model can only be as good as the underlying data - garbage in, garbage out. Learn the basics of working with RGB and Lab images to boost your computer vision projects!Įvery computer vision project - be it a cat/dog classifier or bringing colors to old images/movies - involves working with images.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |