Lab4 task5

Lab4 Task 5 code
%task 5
I =imread('cameraman.tif'); % read the image
subplot(221)
imshow(I),title('orignal')
l=I;
subplot(222);
imhist(I),title('orignal image histogram');
for i=1:1:256
for j=1:256
if(I(i,j)>0 && I(i,j)<32); %setting lower bit zero
I(i,j)=0;
end
end
end
subplot(223)
imhist(I),title('lower bit zero');
for i=1:1:256
for j=1:256
if(l(i,j)>224 && l(i,j)<256); %setting lower bit zero
l(i,j)=0;
end
end
end
subplot(224);
imhist(l),title('heigh bit set zero');

lab4 Task 4 code
%Lab4_Task4)
x=imread('cameraman.tif');%reading image
subplot(1,2,1),imhist(x) %show original histogram
title('Original Histogram') %display title
[m,n]=size(x); %storing size of image
for i=1:m %initiating loop
for j=1:n %initiating loop
if(x(i,j)<50) %finding the lower-order bit planes
x(i,j)=0;
elseif(x(i,j)>200)
%finding the higher-order bit planes
x(i,j)=255; %setting to 255 the higher-order bit planes

end
end
end
subplot(1,2,2),imhist(x) %show transformed histogram
title('Lower Bits Set to zero and Higher Bits Set to 255 ')%display title
Lab4 task4
Lab4 task3

Task2
Lab4 task3 code
i=imread('football.jpg');
j=rgb2gray(i); %read image
k=rgb2gray(i);%% change to gray scale
[m n]=size(j);% geatting size of image
subplot(221)
imshow(k),title('Orignal image'); %display orignal imag
for x=1:m
for y=1:n
if(j(x,y)>200) %getting value greater then 200
j(x,y)=256; %setting values 256
else
j(x,y)=50; %setting values 50
end
end
end
subplot(222)
imshow(j),title('white colored stitches');
for x=1:m
for y=1:n
if(k(x,y)>150 && j(x,y)<200)
k(x,y)=256; %setting intermidiate values 256
end
end
end
subplot(223)
imshow(k,[]),title('stitches between from 150 to 200');

lab4 task 1
x=imread('pout.tif'); %read image
subplot(211);
imshow(x); % display image
title('original image');
a=imadjust(x,[.3 .8]); %contrast streching
%in a range .3 to .8
subplot(212);
imshow(a); %display contrast streching image
title('contrast streching');

lab4 task2 already performed
Lab6_task1(a):
a=imread('cameraman.tif');
subplot(2,2,1);
imshow(a); %display the original image

a1=im2double(a)

x1 = a(256-33,:); %we get 33rd row from bottom
subplot(2,2,2);
plot(x1); %plot the 33rd row from bottom

w=[1 1 1 1 1 1 1]; %taking a vector
x=w/7;
a2=conv2(x1,x,'same'); %convolution of an image
subplot(2,2,3);
plot(a2); %plot the convolution of an image

lab6_task1(b):
%lab6-task1(b)
y=imread('rice.png');
subplot(2,2,1);
imshow(y); %display the original image
title('original image')
yy=im2double(y) %setting image double
x1 = y(:,99);
l=diff(x1); %taking derivative of image
subplot(2,2,2);
plot(l); %plot the derivative of image
x=w/7;
yyy=conv2(x1,x,'same'); %convolution of an image and x equation
subplot(2,2,3);
plot(yyy); %plot the convolution

Lab6_task2:
% task #2
y=imread('Untitled.png'); % read image
q=rgb2gray(y); %change to gray scale
%display image
subplot(2,2,1),imshow(q),title('original image');

q=im2double(q);
x1 = q(:,:);
w=[1 1 1 1 1 1 1]; %row vactor of 1's
x=w/7;
yyy=conv2(x1,x,'same');%convolution of an image and with row vactor
subplot(2,2,2),imshow(yyy);title('row wise operation');
x=x'; %
yyy=conv2(x1,x,'same'); %convolution of an image and with coloum vactor
subplot(2,2,3),imshow(yyy);title('coloumn wise operation');

w=[7 7 7 7 7 7 7]; %row vactor of 7's
x=w/7;
yyy=conv2(x1,x,'same'); %convolution of an image and with a 7/7 vactor
subplot(2,2,4),imshow(yyy);title('7 by 7 ');

Lab6_task3:
f=imread('cameraman.tif'); % read image
f=im2double(f); %change to double formate
a1 = [1 1 1]/3;
yyy=conv2(f,a1,'same'); %convolution of an image and with a filter
subplot(2,3,1),imshow(yyy,[]);title('filter a1');
a2=ones(1,7)/7;
yyy=conv2(f,a2,'same'); %convolution of an image and with a filter
subplot(2,3,2),imshow(yyy,[]);title('filter a2');
a3 = [1 -1];
yyy=conv2(f,a3,'same'); %convolution of an image and with a filter
subplot(2,3,3),imshow(yyy,[]);title('filter a3 ');
a4 = [-1 3 -1];
yyy=conv2(f,a4,'same'); %convolution of an image and with a filter
subplot(2,3,4),imshow(yyy,[]);
title('filter a4 ');
a5 = [-1 1 1 1 -1];
yyy=conv2(f,a5,'same'); %convolution of an image and with a filter
subplot(2,3,5),imshow(yyy,[]);
title('filter a5 ');

Lab6_task4:
y=imread('Untitled.png'); % read image
y=rgb2gray(y); %change to gray scale
xx=im2double(y); %change to double formate
a1 = [-1 -2 -1;0 0 0;1 2 1];
a2 = [-1 -1 -1;-1 8 -1;-1 -1 -1];
a3 = [-1 -1 -1;-1 8+7 -1;-1 -1 -1];
y1=conv2(xx,a1,'same'); %convolution of image and a1 equation
y2=conv2(xx,a2,'same'); %convolution of image and a2 equation
y3=conv2(xx,a3,'same'); %convolution of image and a3 equation
% output through subplot
subplot(2,2,1)
imshow(xx); %display the original image
title('Original image ');
subplot(2,2,2)
imshow(y1,[]); %display first derivative of image
title('single derivative ');
subplot(2,2,3)
imshow(y2,[]); %display the 2nd derivative of image
title('double derivative ');
subplot(2,2,4)
imshow(y3,[]);
title('double derivative with factor');

lab5_task2
im = imread('cameraman.tif');
subplot(2,2,1);
imshow(im);

subplot(2,2,2);
imhist(im);
out = histeq(im, 256); %//or you can use my function: out = hist_eq(im);
subplot(2,2,3);
imshow(out);
subplot(2,2,4);
imhist(out);

lab5_task3:
I = imread('concordaerial.png');
J = imread('concordorthophoto.png');
z = imhistmatch(I,J);
subplot(2,2,1);
imshow(I), %dislay the original image
title('original image');
subplot(2,2,2);
imshow(J), %diplay the original image
title('reference image');
subplot (2,2,3);
imshow(z);
title('output image');

lab5-task4:
%lab5task4
a=imread('rice.png');
a=im2double(a); %double the image
w=input('Enter size: '); %enter the value of
k=input('Enter value of k: '); %enter any constant value
M=mean2(a); %taking mean of image a
z=colfilt(a,[w w],'sliding',@std); %rearranges the columns of the matrix back
into m-by-n
m=colfilt(a,[w w],'sliding',@mean);
eq1=k*M./z;
g=eq1.*(a-m)+m;
subplot(3,3,1)
imshow(a); %display the original image
title('original image');
subplot(3,3,2)
imshow(g);
Task 2 output
I = imread('concordaerial.png');

J = imread('concordorthophoto.png');

z = imhistmatch(I,J);

subplot(2,2,1);

imshow(I), title('original image');

subplot(2,2,2);

imshow(J), title('reference image');

subplot (2,2,3);

imshow(z); title('output image');

Lab6task1(a):
Lab6task1(b):
Lab6task2:
Lab6task3
Lab6task4
Lab5task4:
Lab5task2

Lab5task3