Documente Academic
Documente Profesional
Documente Cultură
Experiment No. 2
Generating Special Images
Object:
The purpose of this experiment is to learn how to generate special image.
Introduction:
In most of image processing algorithms (like denoising, compression, segmentation, etc.), there exist the
need for special images to evaluate the algorithm's ability. Matlab provides tools to generate some of
these images, while mathematical operations are needed to generate other images.
Procedure:
Checkerboard: Matlab provides a direct function to generate a checkerboard like image, with the
ability to decide the number of squares in the board.
I = checkerboard(n,p,q)
where:
n: is the number of pixels per side,
p: is the number of rows,
q: is the number of columns,
Example 1:
I1 = checkerboard;
subplot(1,2,1), imshow(I1)
(1 - 2)
University of Duhok Image Processing Lab
College of Engineering Class: Fourth Year
Electrical and Computer Department 2019-2020
(2 - 2)
University of Duhok Image Processing Lab
College of Engineering Class: Fourth Year
Electrical and Computer Department 2019-2020
Special pattern:
1. Black box inside white area:
f = ones (50, 50);
f (10:40,15:35) = 0;
imshow (f)
(3 - 2)
University of Duhok Image Processing Lab
College of Engineering Class: Fourth Year
Electrical and Computer Department 2019-2020
4. Rotated white line inside black area: such image can be created with the aid of the Matlab
function imrotate:
B = imrotate(A,angle,method,bbox)
where:
A: is the image to be rotated,
angle: is the angle (in degree) of rotation in a counterclockwise direction around the center
point of the image.
method: is the interpolation method.
bbox: specifies the size of the returned image.
image=zeros(100,100);
image(50:52, 1:100) = 1;
J = imrotate(image,30,'bilinear','crop');
imshow(J)
(4 - 2)
University of Duhok Image Processing Lab
College of Engineering Class: Fourth Year
Electrical and Computer Department 2019-2020
Color image: a specific color image can be generated by carefully generating each R – G – B
matrix and then combine them in one matrix
m1 = zeros(300,300);
m1(1:100,1:300) = 0.75;
m2 = zeros(300,300);
m2(101:200,1:300) = 0.75;
m3 = zeros(300,300);
m3(201:300,1:300) = 0.75;
color_img(:,:,1) = m1;
color_img(:,:,2) = m2;
color_img(:,:,3) = m3;
subplot(2,3,1), imshow(m1), title('Red component')
subplot(2,3,2), imshow(m2), title('Green component')
subplot(2,3,3), imshow(m3), title('blue component')
subplot(2,1,2), imshow(color_img), title('The color image')
(5 - 2)
University of Duhok Image Processing Lab
College of Engineering Class: Fourth Year
Electrical and Computer Department 2019-2020
(6 - 2)