Uploaded by dooona.1997

Assignment

advertisement
Assignment #1
Getting Comfortable with MATLAB
Dania Khaled Alamen
Digital Image Processing
EC593
Dr. Esmail Labib
Tripoli University
Computer engineering department
June 22, 2020
1- Do the following for the "cameraman.tif" image:
 Read it into variable I
 Resize it to 256×256 if necessary
 Write a MatLab function for the following procedure:
o Generate two random numbers x and y between 5 and
251
o Construct a white square of size 9×9 around I(x,y)
o Display the modified Image
o Generate two random numbers x and y between 8 and
248
o Invert all pixels of a 15×15 window around I(x,y)
o Set all pixels around the inverted area to 255
o Display the modified Image
-----------------------------------------------------------------main_Script.m
Clear all; clc;
I=imread('cameraman.tif); % load the image
I2=imresize(I,[256,256]); % resize to size 2656*256
% call the function
disp_window(I2);
-------------------------------------------------------------disp_window.m
function disp_window(I)
img=double(I);
% generate random numbers between 5 and 251
r =randi([5,251],[2,1]);
x=r(1); y=r(2);
% generate the window around pixel (x,y)
lrow=x-4; hrow=x+4;
lcol=y-4; hcol=y+4;
% modiy the image
img(lrow:hrow,lcol:hcol)=255; % set pixels to white
imshow(uint8(img)) % display the modified image
title('Image with white color window');
%%
clear img;
img=double(I);
% generate random numbers between 8 and 248
r =randi([8,248],[2,1]);
x=r(1); y=r(2);
% generate the window around pixel (x,y)
lrow=x-7; hrow=x+7;
lcol=y-7; hcol=y+7;
% modiy the image
img(lrow:hrow,lcol:hcol)=imcomplement(I(lrow:hrow,lcol:hcol)); %
set pixels to white
figure;
imshow(uint8(img)) % display the modified image
title('Image with inverted color window');
end
================================ SCREENSHOT OF CODE
=================================== SAMPLE OUTPUT
Download