EXPERIMENT NO.1 Aim: To study reading, displaying and visualization of images. Problem Statement: (a) Read and display different types of images. (b) Convert the image types and image classes. Software: MATLAB (R2008a). Theory: MATLAB provides various tools for image processing. For reading, displaying and visualization of images, we can use following commands: 1. imread Read image from graphics file. Syntax A = imread(filename, fmt) A = imread(filename, fmt) reads a grayscale or color image from the file specified by the string filename. If the file is not in the current directory, or in a directory on the MATLAB path, specify the full pathname. The text string fmt specifies the format of the file by its standard file extension. For example, specify 'gif' for Graphics Interchange Format files. To see a list of supported formats, with their file extensions, use the imformats function. If imread cannot find a file named filename, it looks for a file named filename.fmt. 2. imshow: Display the image. Syntax imshow(I) imshow(I,[low high]) imshow(RGB) imshow(BW) imshow(I) displays the grayscale image I. imshow(I,[low high]) displays the grayscale image I, specifying the display range for I in [low high]. The value low (and any value less than low) displays as black; the value high (and any value greater than high) displays as white. Values in between are displayed as intermediate shades of gray, using the default number of gray levels. If you use an empty matrix () for [low high], imshow uses [min(I(:)) max(I(:))]; that is, the minimum value in I is displayed as black, and the maximum value is displayed as white. imshow(RGB) displays the truecolor image RGB. imshow(BW) displays the binary image BW. imshow displays pixels with the value 0 (zero) as black and pixels with the value 1 as white.
3. rgb2gray: Convert RGB image or colormap to grayscale. Syntax I = rgb2gray(RGB) I = rgb2gray(RGB) converts the truecolor image RGB to the grayscale intensity image I. rgb2gray converts RGB images to grayscale by eliminating the hue and saturation information while retaining the luminance. 4. rgb2hsv: Convert RGB colormap to HSV colormap. Syntax cmap = rgb2hsv(M) cmap = rgb2hsv(M) converts an RGB colormap M to an HSV colormap cmap. Both colormaps are m-by-3 matrices. The elements of both colormaps are in the range 0 to 1. The columns of the input matrix M represent intensities of red, green, and blue, respectively. The columns of the output matrix cmap represent hue, saturation, and value, respectively. 5. rgb2ycbcr: Convert RGB color values to YCbCr color space. Syntax ycbcrmap = rgb2ycbcr(map) YCBCR = rgb2ycbcr(RGB) ycbcrmap = rgb2ycbcr(map) converts the RGB values in map to the YCbCr color space. map must be an M-by-3 array. ycbcrmap is an M-by-3 matrix that contains the YCbCr luminance (Y) and chrominance (Cb and Cr) color values as columns. Each row in ycbcfmap represents the equivalent color to the corresponding row in the RGB colormap, map. YCBCR = rgb2ycbcr(RGB) converts the truecolor image RGB to the equivalent image in the YCbCr color space. RGB must be a M-by-N-by-3 array. 6. gb2ntsc: Convert RGB color values to NTSC color space. Syntax yiqmap = rgb2ntsc(rgbmap) YIQ = rgb2ntsc(RGB) yiqmap = rgb2ntsc(rgbmap) converts the m-by-3 RGB values in rgbmap to NTSC color space. yiqmap is an m-by-3 matrix that contains the NTSC luminance (Y) and chrominance (I and Q) color components as columns that are equivalent to the colors in the RGB colormap. YIQ = rgb2ntsc(RGB) converts the truecolor image RGB to the equivalent NTSC image YIQ. 7. im2double: Convert image to double precision Syntax : I2 = im2double(I)
I2 = im2double(I) converts the intensity image I to double precision, rescaling the data if necessary.If the input image is of class double, the output image is identical. 8. im2uint8: Convert image to 8-bit unsigned integers Syntax: I2 = im2uint8(I1) im2uint8 takes an image as input and returns an image of class uint8. If the input image is of class uint8, the output image is identical to the input image. If the input image is not uint8, im2uint8 returns the equivalent image of class uint8, rescaling or offsetting the data as necessary. 9. im2int16: Convert image to 16-bit signed integers Syntax: I2 = im2int16(I) I2 = im2int16(I) converts the intensity image I to int16, rescaling the data if necessary. If the input image is of class int16, the output image is identical to it. PROGRAM: % Program for reading, displaying & visualization of images % I=imread('C:\Users\user\Desktop\RDL\Forest Flowers.jpg'); subplot(3,2,1); imshow(I); title('original image1'); j=rgb2gray(I); subplot(3,2,2); imshow(j); title('gray image'); m=rgb2hsv(I); subplot(3,2,3); imshow(m); title('color converted image1'); n=rgb2ycbcr(I); subplot(3,2,4);
imshow(n); title('color converted image2'); l=rgb2ntsc(I); subplot(3,2,5); imshow(l); title('color converted image3'); % CONVERTING IMAGES IN DIFFERENT CLASSES% I=imread('C:\Users\Dheeraj\Desktop\tulips.jpg'); subplot(3,2,1); imshow(I); title('original image'); I2=rgb2gray(I); subplot(3,2,2); imshow(I2); title('gray image'); I3 = im2uint16(I2); subplot(3,2,3); imshow(I3); title ('int16 class converted image'); I4 = im2uint16(I3); subplot(3,2,4); imshow(I4); title ('int8 class converted image'); I5 = im2double(I); subplot(3,2,5); imshow(I5); title ('double class converted image'); I6 = im2double(I4); subplot(3,2,6); imshow(I6); title ('double class converted image');