Saturday, 15 November 2014

Reading image in MATLAB



Images are nothing but the two dimensional array of m columns and n rows where x and y are the spatial coordinates. The intensity at any pair of coordinates (x, y) is the amplitude of image at that point. Image may be continuous with respect to x and y coordinates. Different type of images includes intensity images (grayscale images), Color images (RGB images) and binary images. Here we will be using the grayscale images mostly.

  • Intensity image: For an image of m by n matrix range is [0, 1] for class double and [0, 255] for class uint8.
  • Binary images: For an image of m by n matrix range is [0, 1] and often referred as digital image where the intensity of image is finite and discrete quantity.
  • Color image (RGB): For an image of m by n by 3 matrixes range is [0, 1] for class double and [0, 255] for class uint8.

Image Composition
Before moving towards how to reads image in matlab let have looks to the commonly used image formats.



Format
Extensions
JPEG : Joint Photographic Expert Group
.jpg , .jpeg
TIFF : Tagged Image File Format
.tif , .tiff
GIF : Graphics Interchange Format
.gif
BMP : Windows Bitmap
.bmp
PNG : Portable Network Graphics
.png
XWD : X Windows Dump
.xwd


Image Read

The Matlab image read function “imread” is used for reading images.
Syntax:imread(filename);
  x = imread(filename);  Stores image in a variable x.

  • The single quotes (‘’) are used to delimit the string filename.
  • The semicolon (;) at the end of the command line is used for suppressing the output. An imread command with no semicolon at the end will display the image pixel value in command window itself.









image read workspace











The second imread command will save the image in the variable x. Suppose if we had to use the image ten times in our program we would simply call that variable again and again instead of reading the image ten times. 



Image Show

The Matlab image display function “imshow” is used for displaying images.
Syntax:  imshow(variable name);
              imshow(variable name,[]); For proper image scaling.


Displaying the above read image using Imshow
imshow(x,[]);

image show command1

 

 
We can use the nested command foe showing images as well.
imshow(imread(cameraman.tif));

image show command2


 


We can also choose the range of intensities in image to be displayed with a modified imshow command.

imshow(variable name,[low High]);

“Low” is the intensity value displayed as black and “High” is the intensity value displayed as white.

imshow(x,[60 100]);

image show command3
 
 The above imshow command displays the images with the defined low and intensity values  of Low = 60 and high = 100.