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

Dip Lab Programs

Uploaded by

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

Dip Lab Programs

Uploaded by

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

EXPT.

NO 1: SAMPLING & QUANTIZATION

****************PROGRAM FOR SAMPLING & QUANTIZATION ******************


clc;
clear all;
close all;
img=imread('image.JPG');
imshow(img);
I=rgb2gray(imread(uigetfile('*.*','SELECT INPUT IMAGE')));
U=upsample(I,2);
D=downsample(I,2);
T=multithresh(I);
Q=imquantize(I,T);
subplot(221);imagesc(I);title('INPUT IMAGE');
subplot(222);imagesc(U);title('UP SAMPLED IMAGE');
subplot(223);imagesc(D);title('DOWN SAMPLED IMAGE');
subplot(224);imagesc(Q);title('QUANTIZED IMAGE');

INPUT & OUTPUT:


EXPT.NO: 2 SPATIAL AND INTENSITY RESOLUTION OF IMAGE

****************PROGRAM FOR SPATIAL AND INTENSITY RESOLUTION OF IMAGE ******************


clc;
clear all;
close all;
I=rgb2gray(imread(uigetfile('*.*','SELECT INPUT IMAGE' )));
SP=imref2d(size(I));
IA1=imadjust(I,[0 0.25]);
IA2=imadjust(I,[0 0.50]);
IA3=imadjust(I,[0 0.75]);
IA4=imadjust(I,[0 1]);
IA=imadjust(I);

figure();
subplot(221);imagesc(I);title('ORIGINAL IMAGE');
subplot(222);imagesc(I,[0,255]);title('ADJUSTED SPATIAl RANGE OF 256');
subplot(223);imagesc(I,[0,127]);title('ADJUSTED SPATIAl RANGE OF 128');
subplot(224);imshow(I,SP);title('AUTOMATIOCALLY ADJUSTED SPATIAl RANGE');

figure();
subplot(321);imagesc(I);title('ORIGINAL IMAGE');
subplot(322);imagesc(IA1);title('INTENSITY RESOLUTION VALUE OF 0.25');
subplot(323);imagesc(IA2);title('INTENSITY RESOLUTION VALUE OF 0.50');
subplot(324);imagesc(IA3);title('INTENSITY RESOLUTION VALUE OF 0.75');
subplot(325);imagesc(IA4);title('INTENSITY RESOLUTION VALUE OF 1');
subplot(326);imagesc(IA);title('AUTOMATICALLY ADJUSTED IMAGE');

INPUT & OUTPUT:


EXPT.NO: 3 INTENSITY TRANSFORMATION OF IMAGE

****************PROGRAM FOR INTENSITY TRANSFORMATION OF IMAGE *********************


clc;
clear all;
close all;
I=rgb2gray(imread(uigetfile('*.*','SELECT INPUT IMAGE')));

N=imcomplement(I);
G1=imadjust(I,[],[],3);
G2=imadjust(I,[],[],1);
G3=imadjust(I,[],[],0.5);

L1=0.1*log(1+double(I));
L2=0.15*log(1+double(I));
L3=0.2*log(1+double(I));

M=mean2(I);
C1=1./(1+(M./(double(I)+eps)).^4);
C2=1./(1+(M./(double(I)+eps)).^5);
C3=1./(1+(M./(double(I)+eps)).^10);

figure();
subplot(121);imshow(I);title('ORIGINAL IMAGE');
subplot(122);imshow(N);title('NEGATIVE IMAGE');

figure();
subplot(221);imshow(I);title('ORIGINAL IMAGE');
subplot(222);imshow(G1);title('GAMMA VALUE 3');
subplot(223);imshow(G2);title('GAMMA VALUE 1');
subplot(224);imshow(G3);title('GAMMA VALUE 0.5');
figure();
subplot(221);imshow(I);title('ORIGINALIMAGE');
subplot(222);imshow(L1);title('SCALING FUNCTION VALUE 0.1'); subplot(223);imshow(L2);title('SCALING
FUNCTION VALUE 0.15'); subplot(224);imshow(L3);title('SCALING FUNCTION VALUE 0.2');

figure();
subplot(221);imshow(I);title('ORIGINAL IMAGE');
subplot(222);imshow(C1);title('SLOPE FUNCTION VALUE 4'); subplot(223);imshow(C2);title('SLOPE FUNCTION
VALUE 5'); subplot(224);imshow(C3);title('SLOPE FUNCTION VALUE 10');
INPUT & OUTPUT:
EXPT.NO: 4 DFT ANALYSIS

****************PROGRAM FOR DFT ANALYSIS *********************


clc;
clear all;
close all;
S1=im2double(rgb2gray(imread(uigetfile('*.*','SELECT INPUT DATA'))));

S=fft2(S1);
M=abs(S);
P=angle(S);
R=ifft2(S);

[cA,cH,cV,cD]=dwt2(S1,'db1');

RW=idwt2(cA,cH,cV,cD,'db1');

figure();
subplot(221);imshow(S1);title('INPUT IMAGE');
subplot(222);imshow(M);title('MAGNITUDE OF INPUT IMAGE'); subplot(223);imshow(P);title('PHASE ANGLE
OF INPUT IMAGE '); subplot(224);imshow(R);title('RECONSTRUCTION OF INPUT IMAGE ');

figure();
subplot(221);imshow(S1);title('INPUT IMAGE'); subplot(222);imshow(cA);title('APPROXIMATION IMAGE');
subplot(223);imshow(cH);title('HORIZONTAL IMAGE'); subplot(224);imshow(RW);title('RECONSTRUCTION OF
INPUT IMAGE ');

INPUT & OUTPUT:


EXPT.NO: 5 TRANSFORMS ('WALSH-HADAMARD TRANSFROMED IMAGE')

****************PROGRAM FOR TRANSFORMS ('WALSH-HADAMARD TRANSFROMED IMAGE')*****


clc;
clear all;
close all;
I=im2double(rgb2gray(imread(uigetfile('*.*','SELECT INPUT DATA'))));
C=dct2(I);
WH=fwht(I);
[A,H,V,D]=dwt2(I,'haar');
IC=idct2(C);
IWH=ifwht(WH);
IH=idwt2(A,H,V,D,'haar');

figure();
subplot(221);imagesc(I);title('INPUT IMAGE');
subplot(222);imagesc(C);title('COSINE TRANSFORMED IMAGE');
subplot(223);imagesc(WH);title('WALSH-HADAMARD TRANSFROMED IMAGE');
subplot(224);imagesc(A);title('HAAR TRANSFORMED IMAGE');

figure();
subplot(221);imagesc(I);title('INPUT IMAGE');
subplot(222);imagesc(IC);title('RECONSTRUCTION OF COSINE TRANSFORMED IMAGE');
subplot(223);imagesc(IWH);title('RECONSTRUCTION OF WALSH-HADAMARD TRANSFROMED IMAGE');
subplot(224);imagesc(IH);title('RECONSTRUCTION OF HAAR TRANSFORMED IMAGE');

INPUT & OUTPUT:


EXP.NO:06 HISTOGRAM PROCESSING

****************PROGRAM FOR HISTOGRAM PROCESSING *******************


clc;
clear all;
close all;

I=im2double(rgb2gray(imread(uigetfile('*.*','SELECT INPUT DATA'))));

D=imadjust(I,[],[],3);
B=imadjust(I,[],[],0.1);
HEI=histeq(I);
HED=histeq(D);
HEB=histeq(B);

figure();
subplot(221);imshow(I);title('INPUT IMAGE');
subplot(222);imhist(I);title('HISTOGRAM OF INPUT IMAGE');
subplot(223);imshow(HEI);title('HISTOGRAM EQUALIZED INPUT IMAGE');
subplot(224);imhist(HEI);title('HISTOGRAM OF EQUALIZED IMAGE');

figure();
subplot(221);imshow(D);title('LOW INTENSITY IMAGE');
subplot(222);imhist(D);title('HISTOGRAM OF LOW INTENSITY IMAGE ');
subplot(223);imshow(HED);title('HISTOGRAM EQUALIZED LOW INTENSITY IMAGE');
subplot(224);imhist(HED);title('HISTOGRAM OF EQUALIZED LOW INTENSITY IMAGE');

figure();
subplot(221);imshow(B);title('HIGH INTENSITY IMAGE');
subplot(222);imhist(B);title(' HISTOGRAM OF IMAGE ');
subplot(223);imshow(HEB);title('HISTOGRAM EQUALIZED HIGH INTENSITY IMAGE');
subplot(224);imhist(HEB);title('HISTOGRAM OF EQUALIZED HIGH INTENSITY IMAGE');

INPUT & OUTPUT:


EXP.NO:7 IMAGE ENHANCEMENT- SPATIAL FILTERING

****************PROGRAM FOR IMAGE ENHANCEMENT- SPATIAL FILTERING *******************


clc;
clear all;
close all;

I=im2double(rgb2gray(imread(uigetfile('*.*','SELECT INPUT DATA'))));


A=imnoise(I,'salt & pepper');
B=imnoise(I,'poisson');
C=imnoise(I,'gaussian');
D=imnoise(I,'speckle');

M=medfilt2(A);
O=ordfilt2(A,25,true(5));
W=wiener2(A);
H1 = fspecial('gaussian');G=imfilter(A,H1);
H2 = fspecial('log');L=imfilter(A,H2);

M1=medfilt2(B);
O1=ordfilt2(B,25,true(5));
W1=wiener2(B);
H1 = fspecial('gaussian'); G1=imfilter(B,H1);
H2 = fspecial('log'); L1=imfilter(B,H2);

M2=medfilt2(C);
O2=ordfilt2(C,25,true(5));
W2=wiener2(C);
H1 = fspecial('gaussian');G2=imfilter(C,H1);
H2 = fspecial('log');L2=imfilter(C,H2);

M3=medfilt2(D);
O3=ordfilt2(D,25,true(5));
W3=wiener2(D);

H1 = fspecial('gaussian');G3=imfilter(D,H1);

H2 = fspecial('log');L3=imfilter(D,H2);

figure();
subplot(321);imshow(I);title('ORIGINAL IMAGE');
subplot(322);imshow(A);title('ORIGINAL IMAGE WITH SALT & PEPPER NOISE');
subplot(323);imshow(B);title('ORIGINAL IMAGE WITH POISSON NOISE');
subplot(324);imshow(C);title('ORIGINAL IMAGE WITH GAUSSIAN NOISE');
subplot(313);imshow(D);title('ORIGINAL IMAGE WITH SPECKLE NOISE');

figure();
subplot(321);imshow(A);title('ORIGINAL IMAGE WITH SALT & PEPPER NOISE');
subplot(322);imshow(M);title('MEDIAN FILTERED IMAGE'); subplot(323);imshow(O);title('ORDER FILTERED
IMAGE'); subplot(324);imshow(W);title('WIENER FILTERED IMAGE'); subplot(325);imshow(G);title('GAUSSION
FILTERED IMAGE'); subplot(326);imshow(L);title('LAPLACIAN FILTERED IMAGE');

figure();
subplot(321);imshow(B);title('ORIGINAL IMAGE WITH POISSON NOISE');
subplot(322);imshow(M1);title('MEDIAN FILTERED IMAGE'); subplot(323);imshow(O1);title('ORDER FILTERED
IMAGE'); subplot(324);imshow(W1);title('WIENER FILTERED IMAGE');
subplot(325);imshow(G1);title('GAUSSION FILTERED IMAGE'); subplot(326);imshow(L1);title('LAPLACIAN
FILTERED IMAGE');

figure();
subplot(321);imshow(C);title('ORIGINAL IMAGE WITH GAUSSIAN NOISE');
subplot(322);imshow(M2);title('MEDIAN FILTERED IMAGE'); subplot(323);imshow(O2);title('ORDER FILTERED
IMAGE'); subplot(324);imshow(W2);title('WIENER FILTERED IMAGE');
subplot(325);imshow(G2);title('GAUSSION FILTERED IMAGE'); subplot(326);imshow(L2);title('LAPLACIAN
FILTERED IMAGE');

figure();
subplot(321);imshow(D);title('ORIGINAL IMAGE WITH SPECKLE NOISE');
subplot(322);imshow(M3);title('MEDIAN FILTERED IMAGE'); subplot(323);imshow(O3);title('ORDER FILTERED
IMAGE'); subplot(324);imshow(W3);title('WIENER FILTERED IMAGE');
subplot(325);imshow(G3);title('GAUSSION FILTERED IMAGE'); subplot(326);imshow(L3);title('LAPLACIAN
FILTERED IMAGE');

INPUT & OUTPUT:


EXP.NO:08 BASIC MARPHOLOGICAL OPERATIONS

********************PROGRAM FOR BASIC MARPHOLOGICAL OPERATIONS *******************

clc;
clear all;
close all;

I=im2double(rgb2gray(imread(uigetfile('*.*','SELECT INPUT DATA'))));

SE1= strel('line',10,45);
SE2= strel('disk',5);
SE3= strel('square',10);
SE4= strel('diamond',8);
SE5= strel('rectangle',[10 20]);

D1= imdilate(I,SE1);
D2= imdilate(I,SE2);
D3= imdilate(I,SE3);
D4= imdilate(I,SE4);
D5= imdilate(I,SE5);

E1= imerode(I,SE1);
E2= imerode(I,SE2);
E3= imerode(I,SE3);
E4= imerode(I,SE4);
E5= imerode(I,SE5);

ED1= imdilate(E1,SE1);
ED2= imdilate(E2,SE2);
ED3= imdilate(E3,SE3);
ED4= imdilate(E4,SE4);
ED5= imdilate(E5,SE5);

figure();
subplot(321);imshow(I);title('ORIGINAL IMAGE');
subplot(322);imshow(D1);title('IMAGE DILATION USING LINE SHAPE');
subplot(323);imshow(D2);title('IMAGE DILATION USING DISK SHAPE');
subplot(324);imshow(D3);title('IMAGE DILATION USING SQUARE SHAPE');
subplot(325);imshow(D4);title('IMAGE DILATION USING DIAMOND SHAPE');
subplot(326);imshow(D5);title('IMAGE DILATION USING RECTANGULAR SHAPE');

figure();
subplot(321);imshow(I);title('ORIGINAL IMAGE');
subplot(322);imshow(E1);title('IMAGE EROSION USING LINE SHAPE');
subplot(323);imshow(E2);title('IMAGE EROSION USING DISK SHAPE');
subplot(324);imshow(E3);title('IMAGE EROSION USING SQUARE SHAPE');
subplot(325);imshow(E4);title('IMAGE EROSION USING DIAMOND SHAPE');
subplot(326);imshow(E5);title('IMAGE EROSION USING RECTANGULAR SHAPE');

figure();
subplot(321);imshow(I);title('ORIGINAL IMAGE');
subplot(322);imshow(ED1);title('IMAGE EROSION CUM DILATION USING LINE SHAPE');
subplot(323);imshow(ED2);title('IMAGE EROSION CUM DILATION USING DISK SHAPE');
subplot(324);imshow(ED3);title('IMAGE EROSION CUM DILATION SQUARE SHAPE');
subplot(325);imshow(ED4);title('IMAGE EROSION CUM DILATION DIAMOND SHAPE');
subplot(326);imshow(ED5);title('IMAGE EROSION CUM DILATION RECT SHAPE');

INPUT & OUTPUT:


EXP.NO:9 EDGE DETECTION TECHNIQUES

********************PROGRAM FOR EDGE DETECTION TECHNIQUES *******************

clc;
clear all;
close all;

I=im2double(rgb2gray(imread(uigetfile('*.*','SELECT INPUT DATA'))));

s=edge(I,'sobel');
s1=edge(I,'sobel',0.15);
s2=edge(I,'sobel','horizontal');
s3=edge(I,'sobel','vertical');
s4=edge(I,'sobel','both');

c=edge(I,'canny');
c1=edge(I,'canny',0.15);
c2=edge(I,'canny','horizontal');
c3=edge(I,'canny','vertical');
c4=edge(I,'canny','both');

p=edge(I,'prewitt');
p1=edge(I,'prewitt',0.15);
p2=edge(I,'prewitt','horizontal');
p3=edge(I,'prewitt','vertical');
p4=edge(I,'prewitt','both');

r=edge(I,'roberts');
r1=edge(I,'roberts',0.15);
r2=edge(I,'roberts','horizontal');
r3=edge(I,'roberts','vertical');
r4=edge(I,'roberts','both');

% Prewitt Operator:
l=edge(I,'log');
l1=edge(I,'log',[ ]);
l2=edge(I,'log','horizontal');
l3=edge(I,'log','vertical');
l4=edge(I,'log','both');

figure();
subplot(321);imshow(I);title('GRAY SCALE IMAGE');
subplot(322);imshow(s);title('SIMPLE EDGE DETECTION');
subplot(323);imshow(s1);title('SOBEL WITH THRESHOLD');
subplot(324);imshow(s2);title('SOBEL WITH HORIZONTAL');
subplot(325);imshow(s3);title('SOBEL WITH VERTICAL');
subplot(326);imshow(s4);title('SOBEL WITH BOTH DIRECTION');

figure();
subplot(321);imshow(I);title('GRAY SCALE IMAGE');
subplot(322);imshow(c);title('SIMPLE EDGE DETECTION');
subplot(323);imshow(c1);title('CANNY WITH THRESHOLD');
subplot(324);imshow(c2);title('CANNY WITH HORIZONTAL');
subplot(325);imshow(c3);title('CANNY WITH VERTICAL');
subplot(326);imshow(c4);title('CANNY WITH BOTH DIRECTION');

figure();
subplot(321);imshow(I);title('GRAY SCALE IMAGE');
subplot(322);imshow(p);title('SIMPLE EDGE DETECTION');
subplot(323);imshow(p1);title('PREWITT WITH THRESHOLD');
subplot(324);imshow(p2);title('PREWITT WITH HORIZONTAL');
subplot(325);imshow(p3);title('PREWITT WITH VERTICAL');
subplot(326);imshow(p4);title('PREWITT WITH BOTH DIRECTION');

% Laplacian Operator:
figure();
subplot(321);imshow(I);title('GRAY SCALE IMAGE');
subplot(322);imshow(r);title('SIMPLE EDGE DETECTION');
subplot(323);imshow(r1);title('ROBERTS WITH THRESHOLD');
subplot(324);imshow(r2);title('ROBERTS WITH HORIZONTAL');
subplot(325);imshow(r3);title('ROBERTS WITH VERTICAL');
subplot(326);imshow(r4);title('ROBERTS WITH BOTH DIRECTION');

figure();
subplot(321);imshow(I);title('GRAY SCALE IMAGE');
subplot(322);imshow(l);title('SIMPLE EDGE DETECTION');
subplot(323);imshow(l1);title('LAPLACIAN WITH THRESHOLD');
subplot(324);imshow(l2);title('LAPLACIAN WITH HORIZONTAL');
subplot(325);imshow(l3);title('LAPLACIAN WITH VERTICAL');
subplot(326);imshow(l4);title('LAPLACIAN WITH BOTH DIRECTION');

INPUT & OUTPUT:


EXP.NO: 10 IMAGE SEGMENTATION

********************PROGRAM FOR IMAGE SEGMENTATION *******************

clc;
clear all;
close all;

I=im2double(rgb2gray(imread(uigetfile('*.*','SELECT INPUT IMAGE'))));

B=imbinarize(I);
SI=B.*I;

figure();
subplot(221);imshow(I);title('ORIGINAL IMAGE ');
subplot(222);imshow(B);title('BINARY IMAGE');
subplot(212);imshow(SI);title('ROI FROM THE ORIGINAL IMAGE');

INPUT & OUTPUT:


EXP.NO: 11 BASIC THERESHOLDING FUNCTIONS

********************PROGRAM FOR BASIC THERESHOLDING FUNCTIONS*******************

clc;
clear all;
close all;

I=im2double(rgb2gray(imread(uigetfile('*.*','SELECT INPUT IMAGE'))));

T=0.5;
S=wthresh(I,'s',T);
H=wthresh(I,'h',T);

figure();
subplot(221);imshow(I);title('ORIGINAL IMAGE ');
subplot(222);imshow(S);title('SOFT THRESHOLDING');
subplot(212);imshow(H);title('HARD THRESHOLDING');

INPUT & OUTPUT:


EXP.NO : 12 ANALYSIS OF IMAGE WITH DIFERRENT COLOR MODELS

********PROGRAM FOR ANALYSIS OF IMAGE WITH DIFERRENT COLOR MODELS ******************

clc;
clear all;
close all;

RGB=imread(uigetfile('*.*','SELECT INPUT IMAGE'));


R=RGB;
G=RGB;
B=RGB;
R(:,:,2)=0;
R(:,:,3)=0;
G(:,:,1)=0;
G(:,:,3)=0;
B(:,:,1)=0;
B(:,:,2)=0;

subplot(2,2,1);imshow(RGB);title('Original Image');
subplot(2,2,2);imshow(R);title('Red Component');
subplot(2,2,3);imshow(G);title('Green Component');
subplot(2,2,4);imshow(B);title('Blue Component');

INPUT & OUTPUT:

You might also like