SE456 Computer Vision
Assignment # 1
:Submitted On
Tuesday, September 10, 2013
Question 1
Write a matlab code to read the files (owl.pgm and mecca06.pgm) and write these
files with the following names.
owl.pgm should be written as owl_Out.pgm
mecca06.pgm should be written as mecca06_Out.pgm
Code
im1 = imread('D:\Users\Aadil\Desktop\Images\owl.pgm');
im2 = imread('D:\Users\Aadil\Desktop\Images\mecca06.pgm');
figure(1);
imshow(im1);
figure(2);
imshow(im2)
imwrite(im1,'D:\Users\Aadil\Desktop\Images\owl_Out.pgm');
imwrite(im2,'D:\Users\Aadil\Desktop\Images\mecca06_Out.pgm');
Description of Code
I just read the images form desktop and write them again on Desktop destination folder and I also put a code to show them to see that images are correctly loaded or not.
Result
My above code just read the images and save them with different name on desktop folder.
Input Images
Output Image
Question 2
Write a matlab program that do the following:
- a) Reads the files (owl.pgm and mecca06.pgm) in a matrix m1, m2, m3 etc.
- b) Add 50 to each pixel of the matrix (m1, m2 etc.,) using for loop. If pixel value (after adding 50) becomes greater than 255, then assign 255 to that pixel value. Save the matrix in a files (owl_IntensityInc50_Out.pgm, mecca06_IntensityInc50_Out.pgm)
- c) Take the logarithm (log) of base 10 of each pixel of the matrix (m1, m2 etc.)
- and save the matrices in the files (owl_Log_Out.pgm, mecca06_Log_Out.pgm)
Write a matlab program that do the following:
Add 20 to each pixel of the matrix (m1, m2 etc.,) using for loop and save it as
owl_Intensity20_Out.pgm and mecca_Intensity20_Out.pgm.
Add 40 to each pixel of the matrix (m1, m2 etc.,) using for loop and save it as
owl_Intensity40_Out.pgm and mecca_Intensity40_Out.pgm.
Add 60 to each pixel of the matrix (m1, m2 etc.,) using for loop and save it as
owl_Intensity60_Out.pgm and mecca_Intensity60_Out.pgm.
Add 80 to each pixel of the matrix (m1, m2 etc.,) using for loop and save it as
owl_Intensity80_Out.pgm and mecca_Intensity80_Out.pgm.
Add 100 to each pixel of the matrix (m1, m2 etc.,) using for loop and save it as
owl_Intensity100_Out.pgm and mecca_Intensity100_Out.pgm.
- d) Repeat part b and part c without using for loop
Code
%Part A -------------------------------------------------------------------
% read and write both pgm images
im1 = imread('Z:\CV\Images\owl.pgm');
im2 = imread('Z:\CV\Images\mecca06.pgm');
[r1 c1] = size(im1);
[r2 c2] = size(im2);
figure
imshow(im1);
figure
imshow(im2);
imwrite(im1,'Z:\CV\output images\owl_Out.pgm');
imwrite(im2,'Z:\CV\output images\mecca06_Out.pgm');
%part B -------------------------------------------------------------------
% add 50 in both pgm images
for i = 1 : r1
for j = 1 : c1
im1(i,j) = im1(i,j) + 50;
end
end
for i = 1 : r2
for j = 1 : c2
im2(i,j) = im2(i,j) + 50;
end
end
figure
imshow(im1);
figure
imshow(im2);
imwrite(im1,'Z:\CV\output images\owl_IntensityInc50_Out.pgm');
imwrite(im2,'Z:\CV\output images\mecca06_IntensityInc50_Out.pgm');
%part C -------------------------------------------------------------------
% take log of each pixel of each pgm image
for i = 1 : r1
for j = 1 : c1
im1(i,j) = 30 * log10(double(im1(i,j)));
im1(i,j) = uint8(im1(i,j));
end
end
for i = 1 : r2
for j = 1 : c2
im2(i,j) = 30 * log10(double(im2(i,j)));
im2(i,j) = uint8(im2(i,j));
end
end
figure
imshow(im1);
figure
imshow(im2);
imwrite(im1,'Z:\CV\output images\owl_Log_Out.pgm');
imwrite(im2,'Z:\CV\output images\mecca06_Log_Out.pgm');
%part D -------------------------------------------------------------------
% add 20
im1 = imread('Z:\CV\Images\owl.pgm');
im2 = imread('Z:\CV\Images\mecca06.pgm');
for i = 1 : r1
for j = 1 : c1
im1(i,j) = im1(i,j) + 20;
end
end
for i = 1 : r2
for j = 1 : c2
im2(i,j) = im2(i,j) + 20;
end
end
figure
imshow(im1);
figure
imshow(im2);
imwrite(im1,'Z:\CV\output images\owl_Intensity20_Out.pgm');
imwrite(im2,'Z:\CV\output images\mecca06_Intensity20_Out.pgm');
%--------------------------------------------------------------------------
% add 40
im1 = imread('Z:\CV\Images\owl.pgm');
im2 = imread('Z:\CV\Images\mecca06.pgm');
for i = 1 : r1
for j = 1 : c1
im1(i,j) = im1(i,j) + 40;
end
end
for i = 1 : r2
for j = 1 : c2
im2(i,j) = im2(i,j) + 40;
end
end
figure
imshow(im1);
figure
imshow(im2);
imwrite(im1,'Z:\CV\output images\owl_Intensity40_Out.pgm');
imwrite(im2,'Z:\CV\output images\mecca06_Intensity40_Out.pgm');
%--------------------------------------------------------------------------
% add 60
im1 = imread('Z:\CV\Images\owl.pgm');
im2 = imread('Z:\CV\Images\mecca06.pgm');
for i = 1 : r1
for j = 1 : c1
im1(i,j) = im1(i,j) + 60;
end
end
for i = 1 : r2
for j = 1 : c2
im2(i,j) = im2(i,j) + 60;
end
end
figure
imshow(im1);
figure
imshow(im2);
imwrite(im1,'Z:\CV\output images\owl_Intensity60_Out.pgm');
imwrite(im2,'Z:\CV\output images\mecca06_Intensity60_Out.pgm');
%--------------------------------------------------------------------------
% add 80
im1 = imread('Z:\CV\Images\owl.pgm');
im2 = imread('Z:\CV\Images\mecca06.pgm');
for i = 1 : r1
for j = 1 : c1
im1(i,j) = im1(i,j) + 80;
end
end
for i = 1 : r2
for j = 1 : c2
im2(i,j) = im2(i,j) + 80;
end
end
figure
imshow(im1);
figure
imshow(im2);
imwrite(im1,'Z:\CV\output images\owl_Intensity80_Out.pgm');
imwrite(im2,'Z:\CV\output images\mecca06_Intensity80_Out.pgm');
%--------------------------------------------------------------------------
% add 100
im1 = imread('Z:\CV\Images\owl.pgm');
im2 = imread('Z:\CV\Images\mecca06.pgm');
for i = 1 : r1
for j = 1 : c1
im1(i,j) = im1(i,j) + 100;
end
end
for i = 1 : r2
for j = 1 : c2
im2(i,j) = im2(i,j) + 100;
end
end
figure
imshow(im1);
figure
imshow(im2);
imwrite(im1,'Z:\CV\output images\owl_Intensity100_Out.pgm');
imwrite(im2,'Z:\CV\output images\mecca06_Intensity100_Out.pgm');
%part E -------------------------------------------------------------------
% add 50 in both pgm images (part B without using for loop)
im1 = imread('Z:\CV\Images\owl.pgm');
im2 = imread('Z:\CV\Images\mecca06.pgm');
imA = im1 + 50;
imB = im2 + 50;
figure
imshow(imA);
figure
imshow(imB);
imwrite(imA,'Z:\CV\output images\owl_IntensityInc50_Out_without_loop.pgm');
imwrite(imB,'Z:\CV\output images\mecca06_IntensityInc50_Out_without_loop.pgm');
%--------------------------------------------------------------------------
% take log of each pixel of each pgm image (part C without using for loop)
im1 = imread('Z:\CV\Images\owl.pgm');
im2 = imread('Z:\CV\Images\mecca06.pgm');
im1 = log10(double(im1));
im2 = log10(double(im2));
figure
imshow(im1);
figure
imshow(im2);
imwrite(im1,'Z:\CV\output images\owl_Log_Out_without_loop.pgm');
imwrite(im2,'Z:\CV\output images\mecca06_Log_Out_without_loop.pgm');
Description of Code
First of all just read the images from my drive and perform different task.
Special Description:I read both images in each part because of error deduction. And i use the code to show image.
a) I just read the images in rows and columns and save into the matrix. I also use the imshow()keyword to show the images.
b) I have the rows and columns of each image that I have done in part (a). I just add 50 on each pixel usingfor loopand display on screen and save them with the name that has been given in question.
c) In next part as we already have the rows and columns I just use for loop and apply log10 on each pixel and save the output image with different name. Logic:using double because Log2 and Log10 does not support uint8 format it only support double so we take double. Actually our image is uint8 so after taking log we again convert into uint8. And then i save them using new name.
d) Part (D) is all about Part (B). I have just added 20 instead of 50 using for loop.
Next we add 40 then 60 then 80 and last 100. So our output image will brighten and brighten.
e) Now we have to implement part (b) without using for loop so in this part i have just increase 50 in image and save it with different name.
f) In this part i just implement part (c) again now without using for loop. In this part i am using same technique: first i convert into double then take log of whole pic then save it with different name.
Result
a) It just save the image using different name
b) It just adds 50 in each pixel using for loop so my output image become brighten. The condition that has been given in question that make 255 if cost of any pixel become greater than 255. So, MATLAB automatically make the pixel cost 255 if it exceed.
c) After taking a log10 each pixel become low so our image will be looking like following as given in output image section.
d) In this part as we add 40, 60, 80 and 100. My outputs become brightens and brighten.
e) In this part my output become brighten as i add 50 in each pixel.
f) As i apply log10my images become whiten only high intensity black cover has been shown.
Input Images:
Output Image:
Part A output images (Output as it is)
Part B output images (Add 50 each pixel)
Part C output images (Taking log10)
Part D output images (Adding 20, 40, 60, 100)
Part E output images (Adding 50 Without for loop)
Part F output images (using log10 Without for loop)
0 comments:
Post a Comment