Converting a color image into grayscale image


Gray-scale image:
Gray-scale is a range of monochromatic shades from black to white. Therefore, a gray-scale image contains only shades of gray and no color. In a gray-scale image, the hue (apparent color shade) and saturation (apparent color intensity) of each pixel is equal to 0. The lightness (apparent brightness) is the only parameter of a pixel that can vary. Lightness can range from a minimum of 0 (black) to 255 (white) for an 8 bit gray-scale image.

Octave code:
clc;
clear all;
input_image = imread("ubuntu.jpg");
imshow(input_image);
grayscale_image = rgb2gray(input_image);
figure, imshow(grayscale_image); title("Grayscale Image");

Note: Kindly load the image package before executing the code. For more information on how to load packages click here.

Output
Color image converted into grayscale image


Explanation:
The functions imread() and imshow() have been discussed earlier. 
rgb2gray(): The function rgb2gray converts a digital color image into grayscale. If you closely observe the workspace, the variable created grayscale_image (grayscale image) has the class same as that of input_image (the color image) However, the dimensions of the grayscale_image are different from the input_image. The grayscale image (variable: grayscale_image) has dimension 285×285 which indicates that the grayscale image has only one channel i.e., lightness as stated earlier while the color image (variable: input_image) has dimensions 285×285×3.

As already stated a digital image is a two dimensional function of f(x,y), where x and y are spatial coordinates, and the amplitude of f at any pair of coordinates (x,y) is called the intensity of the image at that point. When x, y and the amplitude f are all finite and discrete quantities, we call the image a digital image. Let us now see how a digital grayscale image looks like:
A grayscale digital image
The first value of 255 represents the intensity of f at x = 1 and y = 1 i.e., f(1,1) = 255. The spatial coordinates x and y will vary from 0 to M and 0 to N respectively while amplitude of f can take any value from 0 to 255 for an 8 bit image (uint8 class) based on the intensity.

Comments

Popular posts from this blog

Washing Machine: An example of mechatronics system

Proximity sensors

Piezoelectric Pressure Sensor