Exploring digital images: Interactive design (Part 1)


Let us check whether the input image that we read is a color image or gray-scale image. As discussed earlier a color image has 3 channels (RGB) while a grayscale image has only one channel (brightness/intensity). In order to have, response based interaction with the user we can add interactive message boxes in GNU Octave.

Otcave code:
clc;
clear all;
input_image = imread("google.jpg");
[height width channels] = size(input_image);
imshow(input_image); title("Input Image");
if channels == 3
  msgbox("Input image is color image. Converting input image to grayscale");
  grayscale_image = rgb2gray(input_image);
  figure, imshow(grayscale_image); title("Grayscale Image");
  else
  disp("Input image is grayscale image")
  imshow(input_image);
  end

Output:
Octave code

Interactive message box

Output of the above code
Explanation:
[x,y,z]=size(): The  size function returns the sizes of each dimension of the array. 
Here, the function:
[height width channels] = size(input_image); returns the height, width and no of channels of the input_image
msgbox(): The msgbox function generates an interactive dialog box
Syntax:
-- H = msgbox (MSG)
-- H = msgbox (MSG, TITLE)
-- H = msgbox (MSG, TITLE, ICON)

We have used a if else condition here to convert a color image into grayscale image if the input_image is a color image. In order to check whether the input_image is a color image or grayscale image we check the number of planes available in the input_image. If the number of planes are equal to 3 (i.e., RGB) then the input_image is the color image and is then converted into grayscale using the function rgb2gray().

Comments

Popular posts from this blog

Washing Machine: An example of mechatronics system

Proximity sensors

Piezoelectric Pressure Sensor