Documente Academic
Documente Profesional
Documente Cultură
PRACTICAL-1
INTRODUCTION
The Image Processing Toolbox™ software is a collection of functions that extend the
capability of the MATLAB® numeric computing environment. The toolbox supports a wide
range of image processing operations, including
i. Spatial image transformations
COMMANDS:
1. Imread():= image read command
Syntax:
a = imread(filename, fmt)
Description:
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 informants function. If imread cannot find a file named filename, it
looks for a file named filename.fmt.
Syntax:
B= imshow(a)
Description:
imshow(a) displays the grayscale image a.
Syntax:
imwrite(A,filename,fmt)
Description:
imwrite(A,filename,fmt) writes the image A to the file specified by filename in the
format specified by fmt.
Description:
info = imfinfo(filename,fmt)
It returns a structure whose fields contain information about an image in a graphics file.
Filename is a string that specifies the name of the graphics file, and fmt is a string that specifies
the format of the file. The file must be in the current directory or in a directory on the MATLAB
path. If imfinfo cannot find a file named filename, it looks for a file named filename.fmt. The
possible values for fmt are contained in the MATLAB file format registry. To view of list of
these formats, run the informants command.
Description:
imhist(I) displays a histogram for the image I above a grayscale colorbar. The number of bins
in the histogram is specified by the image type. If I is a grayscale image, imhist uses a default
value of 256 bins. If I is a binary image, imhist uses two bins.
Description:
histeq enhances the contrast of images by transforming the values in an intensity image, or the
values in the colormap of an indexed image, so that the histogram of the output image
approximately matches a specified histogram.
Description:
B = imrotate(A,angle) rotates image A by angle degrees in a counterclockwise direction around
its center point. To rotate the image clockwise, specify a negative value for angle. imrotate
makes the output image B large enough to contain the entire rotated image. imrotate uses
nearest neighbor interpolation, setting the values of pixels in B that are outside the rotated
image to 0 (zero).
Description:
B = imresize(A, scale) returns image B that is scale times the size of A. The input image A can
be a grayscale, RGB, or binary image. If scale is between 0 and 1.0, B is smaller than A. If
scale is greater than 1.0, B is larger than A.
Description:
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.
Description:
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.
Description:
BW = im2bw(I, level) converts the grayscale image I to a binary image. The output image BW
replaces all pixels in the input image with luminance greater than level with the value 1 (white)
and replaces all other pixels with the value 0 (black). You specify level in the range [0,1],
regardless of the class of the input image. The function graythresh can be used to compute the
level argument automatically. If you do not specify level, im2bw uses the value 0.5.
Description:
I = rgb2gray(RGB) converts the true color 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.
Syntax:
Z = imadd(X,Y)
Description:
Z = imadd(X,Y) adds each element in array X with the corresponding element in array
Y and returns the sum in the corresponding element of the output array Z. X and Y are real,
nonsparse numeric arrays with the same size and class, or Y is a scalar double. Z has the same
size and class as X, unless X is logical, in which case Z is double.
If X and Y are integer arrays, elements in the output that exceed the range of the integer type
are truncated, and fractional values are rounded.
Description:
Z = imsubtract(X,Y) subtracts each element in array Y from the corresponding element in array
X and returns the difference in the corresponding element of the output array Z. X and Y are
real, nonsparse numeric arrays of the same size and class, or Y is a double scalar. The array
returned, Z, has the same size and class as X unless X is logical, in which case Z is double.
If X is an integer array, elements of the output that exceed the range of the integer type are
truncated, and fractional values are rounded.
Description:
Z = immultiply(X,Y) multiplies each element in array X by the corresponding element in array
Y and returns the product in the corresponding element of the output array Z.
If X and Y are real numeric arrays with the same size and class, then Z has the same size and
class as X. If X is a numeric array and Y is a scalar double, then Z has the same size and class
as X.
If X is logical and Y is numeric, then Z has the same size and class as Y. If X is numeric and
Y is logical, then Z has the same size and class as X.
immultiply computes each element of Z individually in double-precision floating point. If X is
an integer array, then elements of Z exceeding the range of the integer type are truncated, and
fractional values are rounded
Description:
Z = imdivide(X,Y) divides each element in the array X by the corresponding element in array
Y and returns the result in the corresponding element of the output array Z. X and Y are real,
nonsparse numeric arrays with the same size and class, or Y can be a scalar double. Z has the
same size and class as X and Y.
If X is an integer array, elements in the output that exceed the range of integer type are
truncated, and fractional values are rounded.
MATLAB CODE:
clc;
clear all;
close all;
a = imread('Desert.jpg');
b = imread('Penguins.jpg');
A = imresize(a,[256 256]) %Change size of image subplot(321);
B = imresize(b,[256 256])
subplot(321);
imshow(A)
title('Image A');
subplot(322);
imshow(B)
title('Image B');
%addition
C = imadd(A,B);
subplot(323);
imshow(C)
title('Addition');
%subtraction
D = imsubtract(A,B);
subplot(324);
imshow(D)
title('Subtraction');
%multiplication
E = immultiply(A,B);
subplot(325);
imshow(E)
title('Multiplication');
%division
F = imdivide(A,B);
subplot(326);
imshow(F)
title('Division');
OUTPUT:
MATLAB CODE:
Basic operations:
clc;
clear all;
close all;
a=imread('Hydrangeas.jpg')
subplot(221)
imshow(a)
title('original image')
b=imresize(a,[256,256])
subplot(222)
imshow(b)
title('resize colour image')
c=rgb2gray(b)
subplot(223)
imshow(c)
title('gray image')
d=im2bw(b)
subplot(224)
imshow(d)
title('black and white image')
e=invert(b)
figure;
imshow(e)
OUTPUT:
CONCLUSION:
In this practical, we get introduction to image processing toolbox and all the basic commands
that we can use for processing.