0% found this document useful (0 votes)
3 views

dip lab printout (2)

The document contains MATLAB code for various image processing techniques including 2D linear and circular convolution, discrete Fourier and cosine transforms, image enhancement, threshold operations, edge detection, dilation and erosion, opening and closing operations, and color separation. Each section includes input prompts, processing steps, and output displays of images and results. The code demonstrates practical applications of convolution, Fourier transforms, and image manipulation techniques.

Uploaded by

magimegala1105
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

dip lab printout (2)

The document contains MATLAB code for various image processing techniques including 2D linear and circular convolution, discrete Fourier and cosine transforms, image enhancement, threshold operations, edge detection, dilation and erosion, opening and closing operations, and color separation. Each section includes input prompts, processing steps, and output displays of images and results. The code demonstrates practical applications of convolution, Fourier transforms, and image manipulation techniques.

Uploaded by

magimegala1105
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

2D Linear and Circular Convolution

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]

"convolution sum using direct formula method="


1.
3.
6.
10.
9.
7.
4.
"Circular convolution result="

10. 10. 10. 10.


Discrete Fourier Transform (DFT) and
Discrete Cosine Transform (DCT)

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:

Enter threshold parameter 200


Edge Detection
clc;
a=imread('C:\Users\user\Documents\Capture3.JPG');
a=rgb2gray(a);
c=edge(a,'sobel');
d=edge(a,'prewitt');
e=edge(a,'log');
f=edge(a,'canny');
subplot(2,3,1);
imshow(a)
title('Original Image');
subplot(2,3,2);
imshow(c)
title('sobel');
subplot(2,3,3);
imshow(d)
title('prewitt');
subplot(2,3,4);
imshow(e)
title('log');
subplot(2,3,5);
imshow(f)
title('canny');

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:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy