You are on page 1of 6

University of Duhok Image Processing Lab

College of Engineering Class: Fourth Year


Electrical and Computer Department 2019-2020

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)

I2 = checkerboard (8, 2, 3);


subplot(1,2,2), imshow(I2)

(1 - 2)
University of Duhok Image Processing Lab
College of Engineering Class: Fourth Year
Electrical and Computer Department 2019-2020

 White square: a white image can easily be created by a matrix of '1'.


Example 2:
image = ones([100 100]);
imshow(image)

 Black square: a black image can easily be created by a matrix of '0'.


Example 3:
image = zeros([100 100]);
imshow(image)

 Random-dot: such image can be created by Matlab function rand.


Example 4:
image = rand([100 100]);
imshow (image)

(2 - 2)
University of Duhok Image Processing Lab
College of Engineering Class: Fourth Year
Electrical and Computer Department 2019-2020

Exercise: do the following:


1. Create a 4 × 5 checkboard with 8 pixels for each box.
2. Create a gray square image.

 Special pattern:
1. Black box inside white area:
f = ones (50, 50);
f (10:40,15:35) = 0;
imshow (f)

2. White circle inside black area:


X = ones(100,1)*[-50:49];
Y = [-50:49]'*ones(1,100);
Z = X.^2 + Y.^2;
image = zeros([100 100]);
image(find(Z <= 50^2)) = 1;
imshow(image)

(3 - 2)
University of Duhok Image Processing Lab
College of Engineering Class: Fourth Year
Electrical and Computer Department 2019-2020

Exercise: do the following:


1. Create a white block of 30 × 30 pixels in the center of black box of 300 pixels for eachside.
2. Create a gray circle of 30 pixels radius inside a white box of 200 pixels for eachside.

3. Straight white line inside black area:


image=zeros(100,100);
image(50:52, 1:100) = 1;
imshow(image)

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

Exercise: do the following:


1. Create an image with three black lines each of 5 pixels width in white block of 300 × 300
pixels.
2. Rotate the generated image in (1) by 60° clockwise.

 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

Exercise: do the following:


1. Change the sequences of the pervious image, so that it appears as blue, red and green.
2. Generate a yellow box of 300 × 300 pixel.

(6 - 2)

You might also like