Thursday, 21 November 2013

Study of Read and write different types of images in MATLAB (Binary image, Grayscale image and Color image).

AIM: Read and write different types of images (Binary image, Grayscale image and Color image)


Basically image having three types
1) Binary image: Binary image is the image which having 1 bit/pixel. It has 1 bitplane. Minimum pixel value of image is 0 and maximum is 1.
2) Grayscale Image: Grayscale image is the image having 8 bits/pixel. It has 8 bitplanes. Minimum pixel value of image is 0 and maximum pixel value is 2^8-1  i.e 255 where 8 is number of bits required to represent pixel.
3) Color image: Color image is the image having 24 bits/pixel. It has 3 planes red green and blue. It has 24 bit planes. Minimum pixel value of image is 0 and maximum pixel value is 2^24-1.

Some Image file formats:


Syntax for imread:

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.

Syntax for imwrite:


imwrite(A,filename,fmt) writes the image A to the file specified by filename in the format specified by fmt.
A can be an M-by-N (grayscale image) or M-by-N-by-3 (truecolor image) array, but it cannot be an empty array. For TIFF files, A can be an M-by-N-by-4 array containing color data that uses the CMYK color space. For GIF files, A can be an M-by-N-by-1-by-P array containing grayscale or indexed images — RGB images are not supported. For information about the class of the input array and the output image.
Syntax for Checking size: 

[m,n]= size(X)
m = size(X,dim)
[d1,d2,d3,...,dn] = size(X),

d = size(X) returns the sizes of each dimension of array X in a vector d with ndims(X) elements. If X is a scalar, which MATLAB software regards as a 1-by-1 array, size(X) returns the vector
[1 1].

% Image read Write

[file path]=uigetfile('*.*');
img=imread(file); % Image reading
[r c p]=size(img); %Checking Size

cropped_img=img(100:300,100:300); %Image      Cropping
[file path]=uiputfile('*.bmp');
imwrite(img,[path file]) % Writing Image

1) For Grayscale Image

Grayscale Image
Cropped Image

2) For Color Image
  Color Image

3) For Binary Image

Binary Image 

No comments:

Post a comment