0% found this document useful (0 votes)
125 views

Digital Image Processing

The document discusses performing various image processing operations like resizing, rotating, flipping and zooming an image using MATLAB code. It provides the theory behind each operation and the MATLAB functions used. It then shows the code implemented and outputs the results of applying each operation to a sample image.

Uploaded by

Priyanka Dutta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
125 views

Digital Image Processing

The document discusses performing various image processing operations like resizing, rotating, flipping and zooming an image using MATLAB code. It provides the theory behind each operation and the MATLAB functions used. It then shows the code implemented and outputs the results of applying each operation to a sample image.

Uploaded by

Priyanka Dutta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Digital image processing (EL325)

A laboratory report submitted to


GAUHATI UNIVERSITY INSTITUTE OF SCIENCE AND TECHNOLOGY (GUIST)

GAUHATI UNIVERSITY, GUWAHATI

In partial fulfillment of the requirement for the Degree of Bachelor of Technology

In the

DEPARTMENT

OF

ELECTRONICS AND COMMUNICATION ENGINEERING

GAUHATI UNIVERSITY

Submitted by:
Priyanka Dutta(170101004)
EXPERIMENT NO.-3

AIM:

Write MATLAB code that will do the following:

(a) Image resizing into sizes 2X, 5X, 10X, 0.1X, 0.25X.

(b) Image rotation with and without clipping the corners in angles 10°, 60°, 90°, 110°, 150°.

(c) Image flipping in x and y-axis.

(d) Image Zooming.

(e) Store the images in hard drive using different formats.

THEORY:

The various function we would require are:-

1.Syntax: B = imresize(A,scale)

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 A has more than two dimensions, imresize only resizes the first two
dimensions. If scale is in the range [0, 1], B is smaller than A. If scale is greater than 1, B is larger than A.
By default, imresize uses bicubic interpolation.

2. Syntax: J = imrotate(I,angle)

J = imrotate(I,angle) rotates image I 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
J large enough to contain the entire rotated image. By default, imrotate uses nearest neighbor
interpolation, setting the values of pixels in J that are outside the rotated image to 0.  Syntax: B=
flipdim(A,dim)

3.Syntax: B = flipdim(A,dim)

B = flipdim(A,dim) returns A with dimension dim flipped.When the value of dim is 1, the array is flipped
row-wise down. When dim is 2, the array is flipped columnwise left to right. flipdim(A,1) is the same as
flipud(A), and flipdim(A,2) is the same as fliplr(A).

4. Syntax: imagesc(C)

It displays the data in array C as an image that uses the full range of colors in the colormap. Each element
of C specifies the color for one pixel of the image. The resulting image is an m-by-n grid of pixels where
m is the number of rows and n is the number of columns in C. The row and column indices of the
elements determine the centers of the corresponding pixels.
5.Syntax: imread(filename, fmt )

It reads a greyscale or colour image from the file specified by the string filename , where the string fmt
specifies the format of the file. If the file is not in the current directory or in a directory in the MATLAB
path, specify the full pathname of the location on your system.

6.Syntax:B=imwrite(X,map,filename, fmt )

It writes the indexed image in X and its associated colormap map to filename in the format specified by
fmt . If X is of class uint8 or uint16 , imwrite writes the actual values in the array to the file.

MATLAB CODE:

%% Image resize,roation,flipping,zooming
warning off;
clc;
clear all;
close all;
x=imread('rose.jpg');
figure,imshow(x),title('Original Image')
s=size(x)

%% Image Resize
a=imresize(x,2);
figure,imshow(a),title('Image resized by 2X')
b=imresize(x,5);
figure,imshow(b),title('Image resized by 5X')
c=imresize(x,10);
figure,imshow(c),title('Image resized by 10X')
d=imresize(x,0.25);
figure,imshow(d),title('Image resized by 0.25X')
e=imresize(x,0.1);
figure,imshow(e),title('Image resized by 0.1X')

%% Image rotation without corner clipping


x1=imread('rose.jpg');
figure,subplot(321),imshow(x1),title('Original Image')
a1=imrotate(x1,10);
subplot(322),imshow(a1),title('10°without clipping')
b1=imrotate(x1,60);
subplot(323),imshow(b1),title(' 60°without clipping')
c1=imrotate(x1,90);
subplot(324),imshow(c1),title('90°without clipping')
d1=imrotate(x1,110);
subplot(325),imshow(d1),title('110°without clipping')
e1=imrotate(x1,150);
subplot(326),imshow(e1),title('150°without clipping')
%% Image rotation with corner clipping
x2=imread('rose.jpg');
figure,subplot(321),imshow(x2),title('Original Image')
a2=imrotate(x2,10,'nearest','crop');
subplot(322),imshow(a2),title('10°with clipping')
b2=imrotate(x2,60,'nearest','crop');
subplot(323),imshow(b2),title('60°with clipping')
c2=imrotate(x2,90,'nearest','crop');
subplot(324),imshow(c2),title('90°with clipping')
d2=imrotate(x2,110,'nearest','crop');
subplot(325),imshow(d2),title('110°with clipping')
e2=imrotate(x2,150,'nearest','crop');
subplot(326),imshow(e2),title('150°with cliping ')

%% Image flipping
x3=imread('rose.jpg');
figure,subplot(311),imshow(x3),title('Original Image')
a3=flipdim(x3,2)
subplot(312),imshow(a3),title(' Image flipped along x-axis')
b3=flipdim(x3,1)
subplot(313),imshow(b3),title(' Image flipped along y-axis')

%% Image Zooming
x4=imread('rose.jpg');
figure,subplot(211),imshow(x4),title('Original image')
subplot(212),imagesc(x4),colormap(gray);
title('Zoomed Image')

%% Image Storing
%Resize
imwrite(a,'2X image.tif','jpg');
imwrite(b,'5X image.tif','jpg');
imwrite(c,'10X image.tif','jpg');
imwrite(d,'0.25X image.tif','jpg');
imwrite(e,'0.1X image.tif','jpg');

%Roation without clipping


imwrite(a1,'Image rotated by 10°.tif','jpg');
imwrite(b1,'Image rotated by 60°.tif','jpg');
imwrite(c1,'Image rotated by 90°.tif','jpg');
imwrite(d1,'Image rotated by 110°.tif','jpg');
imwrite(e1,'Image rotated by 150°.tif','jpg');

%Roation with clipping


imwrite(a2,'Image rotated by 10°clip.tif','jpg');
imwrite(b2,'Image rotated by 60°clip.tif','jpg');
imwrite(c2,'Image rotated by 90°clip.tif','jpg');
imwrite(d2,'Image rotated by 110°clip.tif','jpg');
imwrite(e2,'Image rotated by 150°clip.tif','jpg');
%Image Flipping
imwrite(a3,'x-axis flip.tif','jpg');
imwrite(b3,'y-axis flip.tif','jpg');

OUTPUT
RESULTS

1.Image Resize
2.Image Rotation
3.Image Flipping

4.Image Zooming
CONCLUSION:

The above mentioned experiment was completed using the above given MATLAB code thus fulfilling
the objective.The dimension of an image was shown using the function size() and the images were
displayed using the function imshow() and also the images were stored in different formats using the
function imwrite().Here,we have resized,rotated(with and without clipping),flipped and zoomed an
image.

VIVA QUESTIONS:

1) What are the steps involved in digital image processing?

Ans: Fundamental steps in Digital Image Processing :

a. Image Acquisition

This is the first step or process of the fundamental steps of digital image processing. Image acquisition
could be as simple as being given an image that is already in digital form. Generally, the image
acquisition stage involves preprocessing, such as scaling etc.

b. Image Enhancement

Image enhancement is among the simplest and most appealing areas of digital image processing.
Basically, the idea behind enhancement techniques is to bring out detail that is obscured, or simply to
highlight certain features of interest in an image such as, changing brightness & contrast etc.

c. Image Restoration

Image restoration is an area that also deals with improving the appearance of an image. However, unlike
enhancement, which is subjective, image restoration is objective, in the sense that restoration techniques
tend to be based on mathematical or probabilistic models of image degradation.

d. Color Image Processing

Color image processing is an area that has been gaining its importance because of the significant increase
in the use of digital images over the Internet. This may include color modeling and processing in a digital
domain etc.

e. Wavelets and Multiresolution Processing

Wavelets are the foundation for representing images in various degrees of resolution. Images subdivision
successively into smaller regions for data compression and for pyramidal representation.

f. Compression

Compression deals with techniques for reducing the storage required to save an image or the bandwidth to
transmit it. Particularly in the uses of internet it is very much necessary to compress data.
g. Morphological Processing

Morphological processing deals with tools for extracting image components that are useful in the
representation and description of shape.

h. Segmentation

Segmentation procedures partition an image into its constituent parts or objects. In general, autonomous
segmentation is one of the most difficult tasks in digital image processing. A rugged segmentation
procedure brings the process a long way toward successful solution of imaging problems that require
objects to be identified individually.

i. Representation and Description

Representation and description almost always follow the output of a segmentation stage, which usually is
raw pixel data, constituting either the boundary of a region or all the points in the region itself. Choosing
a representation is only part of the solution for transforming raw data into a form suitable for subsequent
computer processing. Description deals with extracting attributes that result in some quantitative
information of interest or are basic for differentiating one class of objects from another.

j. Object recognition

Recognition is the process that assigns a label, such as, “vehicle” to an object based on its descriptors.

k. Knowledge Base:

Knowledge may be as simple as detailing regions of an image where the information of interest is known
to be located, thus limiting the search that has to be conducted in seeking that information. The
knowledge base also can be quite complex, such as an interrelated list of all major possible defects in a
materials inspection problem or an image database containing high-resolution satellite images of a region
in connection with change-detection applications.

2. What do you mean by shrinking of digital image?

Ans: Image shrinking is basically zooming out of a digital image.It is done in a similar manner as just
described for zooming. It involves reduction of pixels and it means loss of irrecoverable information.
EXPERIMENT NO.-4

AIM:

Write MATLAB code that will do the following.

(a) Get your own image and display in MATLAB.

(b) Crop your face from the image.

(c) Store the cropped image in hard drive.

(d) Rotate the cropped image by 45° and save in hard drive.

(e) Remove the corners of the cropped image & again save in hard drive.

(f) Convert the cropped image into grayscale image and save it.

(g) Convert the gray scale image into Binary without using function „im2bw‟.

THEORY:

The various MATLAB functions used are:

1.A = imread(filename, fmt )

It reads a greyscale or colour image from the file specified by the string filename , where the string fmt
specifies the format of the file. If the file is not in the current directory or in a directory in the MATLAB
path, specify the full pathname of the location on your system.

2.J = imcrop(I,rect)

It crops the image I according to the position and dimensions specified in the crop rectangle rect.The crop
rectangle, rect, is a vector of the form [x, y, width, height] that specifies the size and position of the
cropped image in spatial coordinates. The cropped image includes all pixels in the input image that are
completely or partially enclosed by the rectangle.

3.B = imwrite(X,map,filename, fmt )

It writes the indexed image in X and its associated colormap map to filename in the format specified by
fmt . If X is of class uint8 or uint16 , imwrite writes the actual values in the array to the file.
4.J = imrotate( I , angle )

It rotates image I 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 J large enough to
contain the entire rotated image.

5.K= rgb2gray() :

The rgb2gray() function converts RGB images to grayscale by eliminating the hue and saturation
information while retaining the luminance. X = rgb2gray( map ) returns a grayscale colormap equivalent
to map.

MATLAB CODE:

%% Image Cropping and Conversion


warning off;
clc;
clear all;close all;
a=imread('me.jpeg')

%% Image Cropping
c=imcrop(a,[418 3 346 337]);
imwrite(c,'crop.jpg','jpeg');
subplot(221),imshow(a),title('Original Image');impixelinfo;
x=imread('crop.jpg');
subplot(222),imshow(x),title('Cropped Image')

%% Image Roation
g=imrotate(x,45);
subplot(223),imshow(g),title('Rotated Image')
imwrite(g,'crop_rotate.jpg','jpg');
b=imrotate(x,45,'nearest','crop');
subplot(224),imshow(b),title(' Clipped Image')
imwrite(b,'clip_rotate.jpg','jpg');

%% RGB To Grayscale
k=imread('clip_rotate.jpg');
figure;
subplot(311),imshow(k),title(' Clipped Image')
k1=rgb2gray(k);
subplot(312),imshow(k1),title(' Grayscale Image')
imwrite(k1,'gray_converted.jpeg','jpg');

%% Grayscale to Binary
k2=imread('gray_converted.jpeg');
m=mean(k2(:));
k3=k2>m
subplot(313),imshow(k3),title('Binary Image')
imwrite(k3,'gray_converted.jpeg','jpg');
OUTPUT

FIGURE WINDOW
CONCLUSION:

The above mentioned experiment was completed using the above given MATLAB code thus fulfilling
the objective.The images were displayed using the function imshow() and also the images were stored in
different formats using the function imwrite().Here,we have cropped, rotated, corner clipped and
converted an image from one form to another.

You might also like