DIP Lab.2 L5
DIP Lab.2 L5
➢ 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
Laboratory Tasks
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
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