MATLAB
University of Lincoln School of Computer Science CMP3108M – Image Processing
Week-3: Image Manipulation
Last week you were provided with a copy of ‘Matlab Tutorial.pdf’. For today, work your way through Sections 7 (only first two pages), 9, 10, 15, 20 (page 162) and familiarise yourself with the concepts of ‘for loops’, ‘if statements’, data types such as ‘8-bit unsigned integer’, and plotting.
The download the “SampleImages” zip file, un-compress the file, and save the files in your working folder.
Tasks
Write a MATLAB script to create an image of size 200×200 with a black background and white circle with radius of 80 pixels centred at the centre of the image.
Tips:
The distance between two pixels with known coordinates (x1,y1) and (x2,y2) can be calculated in MATLAB as D = sqrt ( (x1-x2)^2 + (y1-y2)^2 );
You can create a 2D matrix of type uint8 by A = uint8(zeros( no of rows, no of columns ));
Now create the image with the white background and black circle.
Then create an image similar to the previous one (black background and white circle), but the circle should be graded (dark on the left side and bright on the right).
Based on the previous steps, creating the below image should be easy, right?!
Write a MATLAB script to load an image and convert it to grey-scale. Then obtain the transpose of image and display it.
Write a MATLAB script to load an image and convert it to grey-scale. Then flip it either vertical or horizontal (example shown below).
Write a MATLAB script to load an image and convert it to grey-scale. Then crop the image and display the cropped image. You can define the desired coordinated by using the “Data Cursor” icon from the top menu as discussed last week.
Tip: you can use the nested loop below:
ROW = 0;
for row = row1:row2
ROW = ROW + 1;
COL = 0;
for col = col1:col2
COL = COL + 1;
B(ROW,COL) = A(row,col);
end end
Write a MATLAB script to load an image and convert it to grey-scale. Then reduce the number of grey levels in the loaded image to 8 (e.g., [0,31,65,…255]). Display both images (original and modified) in a figure side by side and using MATLAB command subplot. You can use the command colorbar; to display the range of colours in the image.
Additional Challenges
Write a MATLAB script to load an image and convert it to grey-scale. Then rotate the image counter- clockwise about its centre by an angle θ. You can use the built-in functions such as cart2pol ,radtodeg, degtorad, pol2cart.
Tip: follow these steps:
Find the midpoints of the image.
Convert the each pixel co-ordinate to polar co-ordinate using cart2pol command.
The result of conversion will yield angle and radius.
Convert the angle which is in radians into degree by using the function rad2deg(theta)
Add the degree value to be rotated to the value obtained in the above step.
Now again convert the degree to radian by using rad2deg function
Finally, convert to Cartesian co-ordinate by using the function pol2cart (theta,radius)