Sunteți pe pagina 1din 8

FUNDAMENTALS OF IMAGE PROCESSING

PRACTICAL-1

AIM: Introduction to image processing toolbox.

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

ii. Morphological operation

iii. Neighbourhood and block operations

iv. Linear filtering and filter design


v. Transforms

vi. Image analysis and enhancement

vii. Image registration


viii. Deburring

ix. Region of interest operations

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.

DESAI JINAL 130420111029


FUNDAMENTALS OF IMAGE PROCESSING

2. Imshow():= Display image

Syntax:
B= imshow(a)

Description:
imshow(a) displays the grayscale image a.

3. Imwrite():= Write image to graphics file

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.

4. Imfinfo():= Return information about graphics file


Syntax:
info = imfinfo(filename,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.

5. imhist():= display histogram of image data


Syntax:
imhist(I)

DESAI JINAL 130420111029


FUNDAMENTALS OF IMAGE PROCESSING

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.

6. histeq():= enhance contrast using histogram equalization


Syntax:
J = histeq(I, hgram);

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.

7. imrotate():= rotate an image


Syntax:
B = imrotate(A,angle)

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).

8. imresize():= resize image


Syntax:
B = imresize(A, scale);

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.

9. im2uint8():=convert image to 8-bit unsigned integers


Syntax:
I2 = im2uint8(I1)

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.

DESAI JINAL 130420111029


FUNDAMENTALS OF IMAGE PROCESSING

10. im2double():=Convert image to double precision


Syntax:
I2 = im2double(I)

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.

11. im2bw():= Convert image to binary image, based on threshold


Syntax:
BW = im2bw(I, level)

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.

12. rgb2gray():= Convert RGB image or colormap to grayscale


Syntax:
I = rgb2gray(RGB)

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.

13. imadd():= to add two image

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.

DESAI JINAL 130420111029


FUNDAMENTALS OF IMAGE PROCESSING

14. imsubtract():= subtract one image from an another image


Syntax: :
Z = imsubtract(X,Y)

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.

15. immultipy():= multiply two images 0r multiply image by constant


Syntax:
Z = immultiply(X,Y)

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

16. imdivide():= divide one image byother or divide image by constant


Syntax:
Z = imdivide(X,Y)
J = imdivide(I,2);

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.

DESAI JINAL 130420111029


FUNDAMENTALS OF IMAGE PROCESSING

MATLAB CODE:

Basic arithmetic operation on image:-

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');

DESAI JINAL 130420111029


FUNDAMENTALS OF IMAGE PROCESSING

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)

DESAI JINAL 130420111029


FUNDAMENTALS OF IMAGE PROCESSING

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.

DESAI JINAL 130420111029

S-ar putea să vă placă și