dip lab printout (2)
dip lab printout (2)
clc;
clear all;
close;
x=input('Enter x seq');
h=input('Enter h seq');
m=length(x);
n=length(h);
for i=1: n+m-1
conv_sum=0;
for j=1:i
if(((i-j+1)<=n)&(j<=m))
conv_sum=conv_sum+x(j)*h(i-j+1);
end;
y(i)=conv_sum;
end;
end;
disp(y,'convolution sum using direct formula method=');
A=fft(x);
B=fft(h);
C=A.*B;
C=ifft(C);
disp(C,'Circular convolution result=');
OUTPUT:
Enter x seq[1 2 3 4]
Enter h seq[1 1 1 1]
clc;
img=[1 1 1 1;1 1 1 1;1 1 1 1; 1 1 1 1]
disp('Image as Matrix')
disp(img);
dc=fft(img);
disp('DCT')
disp(dc);
df=fft(img);
disp('DFT')
disp(df);
OUTPUT:
"Image as Matrix"
1. 1. 1. 1.
1. 1. 1. 1.
1. 1. 1. 1.
1. 1. 1. 1.
"DCT"
16. 0. 0. 0.
0. 0. 0. 0.
0. 0. 0. 0.
0. 0. 0. 0.
"DFT"
16. 0. 0. 0.
0. 0. 0. 0.
0. 0. 0. 0.
0. 0. 0. 0.
Image Enhancement
clc;
close;
a=imread('C:\Users\user\Documents\Saved Pictures\img.jpg');
subplot(2,3,1)
imshow(a);
title('Original Image')
a=rgb2gray(a);
b=double(a)+50;
b=uint8(b);
subplot(2,3,2);
imshow(a);
title('Gray scale Image')
subplot(2,3,3);
imshow(b);
title('Bright Enhanced Image')
c=double(a)*0.5;
c=uint8(c)
d=double(c)*2;
d=uint8(d)
subplot(2,3,4)
imshow(c);
title('Decrease in contrast')
subplot(2,3,5)
imshow(d);
title('Increase in contrast')
k=255-double(a);
k=uint8(k);
subplot(2,3,6)
imshow(k);
title('Negative Image')
OUTPUT:
Threshold Operation
clc;
close;
a=imread('C:\Users\user\Documents\Capture3.JPG');
a=rgb2gray(a);
[m,n]=size(a);
t=input('Enter the threshold parameter');
for i=1:m
for j=1:n
if(a(i,j)<t)
b(i,j)=0;
else
b(i,j)=255;
end
end
end
subplot(1,2,1);
imshow(a)
title('original image');
subplot(1,2,2);
imshow(b)
title('threshold image');
xlabel(sprintf('threshold value is %g',t));
OUTPUT:
OUTPUT:
Dilation and Erosion
img=imread('C:\Users\user\Pictures\Saved Pictures\img.jpg');
subplot(2,3,1);
title('Original Image');
imshow(img);
img1=1-img;
subplot(2,3,2);
title('Binary Image');
imshow(img1);
se=ones(10,10);
see=imcreatese('rect',3,3);
e=imerode(img1,see);
subplot(2,3,3);
title('Erotion Image')
imshow(e);
d=imdilate(img1,see);
subplot(2,3,4);
title('Dilation Image')
imshow(d);
OUTPUT:
Opening and Closing Operation
clc;
f=imread('C:\Users\user\Documents\Saved Pictures\back.jpg');
subplot(2,3,1)
imshow(f);
title('Original Image')
gr=rgb2gray(f);
subplot(2,3,2)
imshow(gr);
title('Gray Image')
se=imcreatese('rect',3,3)
op=imopen(gr,se)
subplot(2,3,3)
imshow(op);
title('Open operation')
clo=imclose(gr,se)
subplot(2,3,4)
imshow(clo);
title('Close operation')
OUTPUT:
Color separation
l=imread('C:\Users\user\Documents\Saved Pictures\back.jpg');
subplot(2,2,1);
imshow(l);
red=l;
red(:,:,[2 3])=0;
subplot(2,2,2);
imshow(red);
title('RED');
blue=l;
blue(:,:,[1 2])=0;
subplot(2,2,3);
imshow(blue);
title('BLUE');
green=l;
green(:,:,[1 3])=0;
subplot(2,2,4);
imshow(green);
title('GREEN');
OUTPUT: