
- Scikit Image – Introduction
- Scikit Image - Image Processing
- Scikit Image - Numpy Images
- Scikit Image - Image datatypes
- Scikit Image - Using Plugins
- Scikit Image - Image Handlings
- Scikit Image - Reading Images
- Scikit Image - Writing Images
- Scikit Image - Displaying Images
- Scikit Image - Image Collections
- Scikit Image - Image Stack
- Scikit Image - Multi Image
- Scikit Image - Data Visualization
- Scikit Image - Using Matplotlib
- Scikit Image - Using Ploty
- Scikit Image - Using Mayavi
- Scikit Image - Using Napari
- Scikit Image - Color Manipulation
- Scikit Image - Alpha Channel
- Scikit Image - Conversion b/w Color & Gray Values
- Scikit Image - Conversion b/w RGB & HSV
- Scikit Image - Conversion to CIE-LAB Color Space
- Scikit Image - Conversion from CIE-LAB Color Space
- Scikit Image - Conversion to luv Color Space
- Scikit Image - Conversion from luv Color Space
- Scikit Image - Image Inversion
- Scikit Image - Painting Images with Labels
- Scikit Image - Contrast & Exposure
- Scikit Image - Contrast
- Scikit Image - Contrast enhancement
- Scikit Image - Exposure
- Scikit Image - Histogram Matching
- Scikit Image - Histogram Equalization
- Scikit Image - Local Histogram Equalization
- Scikit Image - Tinting gray-scale images
- Scikit Image - Image Transformation
- Scikit Image - Scaling an image
- Scikit Image - Rotating an Image
- Scikit Image - Warping an Image
- Scikit Image - Affine Transform
- Scikit Image - Piecewise Affine Transform
- Scikit Image - ProjectiveTransform
- Scikit Image - EuclideanTransform
- Scikit Image - Radon Transform
- Scikit Image - Line Hough Transform
- Scikit Image - Probabilistic Hough Transform
- Scikit Image - Circular Hough Transforms
- Scikit Image - Elliptical Hough Transforms
- Scikit Image - Polynomial Transform
- Scikit Image - Image Pyramids
- Scikit Image - Pyramid Gaussian Transform
- Scikit Image - Pyramid Laplacian Transform
- Scikit Image - Swirl Transform
- Scikit Image - Morphological Operations
- Scikit Image - Erosion
- Scikit Image - Dilation
- Scikit Image - Black & White Tophat Morphologies
- Scikit Image - Convex Hull
- Scikit Image - Generating footprints
- Scikit Image - Isotopic Dilation & Erosion
- Scikit Image - Isotopic Closing & Opening of an Image
- Scikit Image - Skelitonizing an Image
- Scikit Image - Morphological Thinning
- Scikit Image - Masking an image
- Scikit Image - Area Closing & Opening of an Image
- Scikit Image - Diameter Closing & Opening of an Image
- Scikit Image - Morphological reconstruction of an Image
- Scikit Image - Finding local Maxima
- Scikit Image - Finding local Minima
- Scikit Image - Removing Small Holes from an Image
- Scikit Image - Removing Small Objects from an Image
- Scikit Image - Filters
- Scikit Image - Image Filters
- Scikit Image - Median Filter
- Scikit Image - Mean Filters
- Scikit Image - Morphological gray-level Filters
- Scikit Image - Gabor Filter
- Scikit Image - Gaussian Filter
- Scikit Image - Butterworth Filter
- Scikit Image - Frangi Filter
- Scikit Image - Hessian Filter
- Scikit Image - Meijering Neuriteness Filter
- Scikit Image - Sato Filter
- Scikit Image - Sobel Filter
- Scikit Image - Farid Filter
- Scikit Image - Scharr Filter
- Scikit Image - Unsharp Mask Filter
- Scikit Image - Roberts Cross Operator
- Scikit Image - Lapalace Operator
- Scikit Image - Window Functions With Images
- Scikit Image - Thresholding
- Scikit Image - Applying Threshold
- Scikit Image - Otsu Thresholding
- Scikit Image - Local thresholding
- Scikit Image - Hysteresis Thresholding
- Scikit Image - Li thresholding
- Scikit Image - Multi-Otsu Thresholding
- Scikit Image - Niblack and Sauvola Thresholding
- Scikit Image - Restoring Images
- Scikit Image - Rolling-ball Algorithm
- Scikit Image - Denoising an Image
- Scikit Image - Wavelet Denoising
- Scikit Image - Non-local means denoising for preserving textures
- Scikit Image - Calibrating Denoisers Using J-Invariance
- Scikit Image - Total Variation Denoising
- Scikit Image - Shift-invariant wavelet denoising
- Scikit Image - Image Deconvolution
- Scikit Image - Richardson-Lucy Deconvolution
- Scikit Image - Recover the original from a wrapped phase image
- Scikit Image - Image Inpainting
- Scikit Image - Registering Images
- Scikit Image - Image Registration
- Scikit Image - Masked Normalized Cross-Correlation
- Scikit Image - Registration using optical flow
- Scikit Image - Assemble images with simple image stitching
- Scikit Image - Registration using Polar and Log-Polar
- Scikit Image - Feature Detection
- Scikit Image - Dense DAISY Feature Description
- Scikit Image - Histogram of Oriented Gradients
- Scikit Image - Template Matching
- Scikit Image - CENSURE Feature Detector
- Scikit Image - BRIEF Binary Descriptor
- Scikit Image - SIFT Feature Detector and Descriptor Extractor
- Scikit Image - GLCM Texture Features
- Scikit Image - Shape Index
- Scikit Image - Sliding Window Histogram
- Scikit Image - Finding Contour
- Scikit Image - Texture Classification Using Local Binary Pattern
- Scikit Image - Texture Classification Using Multi-Block Local Binary Pattern
- Scikit Image - Active Contour Model
- Scikit Image - Canny Edge Detection
- Scikit Image - Marching Cubes
- Scikit Image - Foerstner Corner Detection
- Scikit Image - Harris Corner Detection
- Scikit Image - Extracting FAST Corners
- Scikit Image - Shi-Tomasi Corner Detection
- Scikit Image - Haar Like Feature Detection
- Scikit Image - Haar Feature detection of coordinates
- Scikit Image - Hessian matrix
- Scikit Image - ORB feature Detection
- Scikit Image - Additional Concepts
- Scikit Image - Render text onto an image
- Scikit Image - Face detection using a cascade classifier
- Scikit Image - Face classification using Haar-like feature descriptor
- Scikit Image - Visual image comparison
- Scikit Image - Exploring Region Properties With Pandas
Scikit Image - Conversion Between Color & Gray Values
Color images can be represented using different color spaces, and one of the most common and widely used color spaces is the RGB color space. In the RGB color space, an image is represented by three separate channels: the red channel (R), the green channel (G), and the blue channel (B). Each channel represents the intensity of its respective color component at each pixel location in the image.
The RGB color model is an additive model used to create colors by combining red, green, and blue light. It is primarily used for sensing, representing, and displaying images in electronic systems, such as computers and televisions.
Color Images in Scikit
In scikit-image, an RGB image is represented as a NumPy array with three channels: Red, Green, and Blue. Each channel's values range from 0 to 1 for floating-point images or from 0 to 255 for 8-bit images. Typically, the RGB image array has a shape of [height, width, 3].
On the other hand, grayscale images are represented by a single channel that contains only the intensity values of each pixel. Grayscale images are often used when color information is not necessary or when working with black-and-white images.
The Scikit-Image library provides functions like rgb2gray and gray2rgb to do conversions between color and gray values.
Converting RGB image to a Grayscale image
The color.rgb2gray() method in the scikit-image library is used to compute the luminance of an RGB image. It takes an input RGB image and returns a grayscale image representing the luminance.
The luminance value of each grayscale pixel is calculated as the weighted sum of the corresponding red, green, and blue pixels using the formula:
Y = 0.2125 R + 0.7154 G + 0.0721 B
These weights are based on the perception of red, green, and blue by human vision and are commonly used by CRT phosphors.
Note:If the input image has an alpha channel, then the method will ignore it.
Syntax
Following is the syntax of this function −
skimage.color.rgb2gray(rgb, *, channel_axis=-1)
The parameter rgb is an array-like object representing the input image in RGB format.
This method returns an ndarray representing the luminance image, which is the same size as the input array but with the channel dimension removed.
Example
In the following example, the color.rgb2gray() method will convert a color image to a grayscale image.
from skimage import color, io import matplotlib.pyplot as plt # Read an RGB image rgb_image = io.imread('Images/image_.jpg') print('Shape of the input RGB image array:',rgb_image.shape) # Convert RGB to Gray gray_image = color.rgb2gray(rgb_image) # Print the result print('Shape of the output Gray image array:',gray_image.shape) # Display the RGB and Gray images fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 8)) axes[0].imshow(rgb_image) axes[0].set_title('Input RGB Image') axes[0].axis('off') axes[1].imshow(gray_image, cmap=plt.cm.gray) axes[1].set_title('Output Gray Image') axes[1].axis('off') plt.tight_layout() plt.show()
Output
On executing the above program, you will get the following output −
Shape of the input RGB image array: (246, 462, 3) Shape of the output Gray image array: (246, 462)

Converting Grayscale image to RGB image
This method is used to create an RGB representation of a gray-level image. If the input image is 1-dimensional with shape (M, ), the output RGB image will have shape (M, 3), where each grayscale pixel value is repeated three times to create an RGB representation. Following is the syntax of this method.
skimage.color.gray2rgb(image, *, channel_axis=-1)
The method accepts the following parameters −
- image: It is an array-like object representing the input gray-level image.
- channel_axis: An optional parameter indicating which axis of the output array will correspond to channels.
This method returns an ndarray representing the RGB image. A new dimension of length 3 is added to the input image, representing the RGB channels.
Example
The following example demonstrates the conversion of a grayscale image to an RGB image using color.gray2rgb() method.
from skimage import color, io import matplotlib.pyplot as plt # Read an RGB image as a grayscale image gray_image = io.imread('F:/Images/Fruits.jpg', as_gray=True) print('Shape of the input Gray image array:', gray_image.shape) # Convert Gray to RGB rgb_image = color.gray2rgb(gray_image) # Print the result print('Shape of the output RGB image array:', rgb_image.shape) # Display the grayscale and RGB images fig, axes = plt.subplots(nrows=2, ncols=1, figsize=(10, 10)) axes[0].imshow(gray_image) axes[0].set_title('Input Gray Image') axes[0].axis('off') axes[1].imshow(rgb_image) axes[1].set_title('Output RGB Image') axes[1].axis('off') plt.tight_layout() plt.show()
Output
When you run the above program, it will produce the following output −
Shape of the input Gray image array: (257, 698) Shape of the output RGB image array: (257, 698, 3)
