0% found this document useful (0 votes)
10 views5 pages

DIP Lab.2 L5

The document outlines a laboratory exercise focused on image processing techniques, including image histogram analysis, color separation, cropping, and rotation using MATLAB. It provides detailed tasks with syntax examples for each operation, demonstrating how to manipulate and analyze image data. The exercises aim to enhance understanding of image geometry operations and data reduction processes in digital image processing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

DIP Lab.2 L5

The document outlines a laboratory exercise focused on image processing techniques, including image histogram analysis, color separation, cropping, and rotation using MATLAB. It provides detailed tasks with syntax examples for each operation, demonstrating how to manipulate and analyze image data. The exercises aim to enhance understanding of image geometry operations and data reduction processes in digital image processing.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Digital Image Processing Laboratory

Lab.2: Image Histogram and Image Geometry Operations (1).

➢ Image Analysis: Manipulating the image data to determine exactly the information necessary to help solve a
computer imaging problem, primarily a data reduction process

Data Reduction

Figure (1): Image analysis process model.

Laboratory Tasks

➢ [Task 1: Finding Image Histogram]


Histogram is bar-graph used to profile the occurrence of each gray level in the image.
Syntax:
imhist(I)
Where I is the image array
Example:
[n,p]=uigetfile({'*.bmp;*.jpg;*.gif','Choose Poorly scanned Image'});
myimage=imread([p n]);
if(size(myimage,3)==3)
myimage =rgb2gray(myimage);
end
subplot(2,1,1);imshow(myimage); title('Original image');
subplot(2,1,2);imhist(myimage); title('image histogram');
➢ [Task 2: Separate color image into three separate R,G,B planes, then combine them
again]

1
myImage=imread('peppers.png');
RED=myImage(:,:,1);
GREEN=myImage(:,:,2);
BLUE=myImage(:,:,3);
newImage=cat(3,RED,GREEN,BLUE);
subplot(3,3,2),imshow(myImage)
subplot(3,3,4),imshow(RED)
subplot(3,3,5),imshow(GREEN)
subplot(3,3,6),imshow(BLUE)
subplot(3,3,8),imshow(newImage)
➢ [Task 3: cropping an image]
1- Using built-in MATLAB function:
Syntax:
I2 = imcrop(I)
displays the image I in a figure window and creates a
cropping tool associated with that image.
I2 = imcrop(I,RECT)
RECT is a 4-element vector with the form [XMIN YMIN WIDTH HEIGHT] which is the area
to be cropped from the image.

XMIN XMIN+WIDTH

YMIN
HEIGH

Cropped Area
T

YMIN+HEIGHT
WIDTH

2- Without using built-in MATLAB function:


function [ y ] = Crop( I,area )
% user definded function to crop an image with a given area
% area=[xmin ymin width hight]

2
if (size(I,3)==1)
xmin=area(1);
ymin=area(2);
width=area(3);
hight=area(4);
if (xmin<1)
xmin=1;
end
if (ymin<1)
ymin=1;
end
y=I(ymin:ymin+hight,xmin:xmin+width);
elseif (size(I,3)==3)
for K=1:3
y(:,:,K)=Crop(I(:,:,K),area);
end
end
end
❖ script for testing the function Crop:
clc
[n,p]=uigetfile();I=imread([p n]);
[A,area]=imcrop(I);
y=Crop(I,area);
subplot(2,3,2),imshow(I),title('original image');
subplot(2,3,4),imshow(A),title('Matlab function ');
subplot(2,3,6),imshow(y),title('User defined function ');

3
➢ [Task 4: Rotating an image by a given angle]
❖ The rotation process requires the use of these equations:

where rˆ and cˆ are the new coordinates, r and c are the original coordinates, and θ is the angle to rotate
the image. θ is defined in a clockwise direction from the horizontal axis at the image origin in the
upper left corner.
Syntax:
B=imrotate(A,angle,mode)
Rotates image A by angle degrees in a counterclockwise direction around its center point.
Where mode is a text string that can have either of the following values. The default value is
'loose'
'loose' Make output image B large enough to contain the
entire rotated image. B is generally larger than A.
'crop' Make output image B the same size as the input image
A, cropping the rotated image to fit.
Example:
clc
[n,p]=uigetfile();
I=imread([p n]);
y=imrotate(I,45);
subplot(2,2,1); imshow(y); title('Image rotated by 45 degree with
loose');
y=imrotate(I,45,'crop');
subplot(2,2,2); imshow(y); title('Image rotated by 45 degree with
crop');
y=imrotate(I,90,'crop');
subplot(2,2,3); imshow(y); title('Image rotated by 90 degree');
y=imrotate(I,-45,'crop');
subplot(2,2,4); imshow(y); title('Image rotated by -45 degree');\

4
Eng./ Maged Albadany

You might also like