0% found this document useful (0 votes)
15 views12 pages

Dip Lab Main Report

The document outlines a series of laboratory exercises focused on image processing techniques using MATLAB. Each lab covers different objectives such as displaying images, brightness adjustments, gray level slicing, logarithmic transformations, noise addition and filtering, edge detection, and Fourier transforms. Input codes for each lab are provided, demonstrating various image manipulation methods and their outputs.
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)
15 views12 pages

Dip Lab Main Report

The document outlines a series of laboratory exercises focused on image processing techniques using MATLAB. Each lab covers different objectives such as displaying images, brightness adjustments, gray level slicing, logarithmic transformations, noise addition and filtering, edge detection, and Fourier transforms. Input codes for each lab are provided, demonstrating various image manipulation methods and their outputs.
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/ 12

1.

BASICS
OBJECTIVE :- DISPLAYING AN IMAGE
INPUT CODE:-
clear all;
close all;
clc;
I=imread('cameraman.tif');
imshow(I)
[m n]=size(I);

OUTPUT :-

2. LAB 1
OBJECTIVE :- Brightness Increase and Decrease, Image Negative, Contrast adjustment
and Hard Thresholding of an image.
INPUT CODE :-
%lab 1 basic operations
clc
close all
clear all
I=imread('lena.tif');
imshow(I), title('Original Image');
I1=rgb2gray(I);
figure,imshow(I1);

%Brigthness increase
I2=I1+50;
figure,imshow(I2)

%Brightness Supression

I3=I1-50;
figure, imshow(I3)

%image negative

I4=255-I1;
figure, imshow(I4);

subplot(221), imshow(I1);
subplot(222), imshow(I2);
subplot(223), imshow(I3);
subplot(224), imshow(I4);

%contrast adjustment(increase)

I5=I1*1.5;
figure, imshow(I5);

%contrast adjustment(decrease)

I6=I1*0.5;
figure, imshow(I6);

subplot(231), imshow(I1), title('Gray scale');


subplot(232), imshow(I2), title('Brightness increase');
subplot(233), imshow(I3), title('Brightness decrease');
subplot(234), imshow(I4), title('Image Negative');
subplot(235), imshow(I5), title('Contrast Increase');
subplot(236), imshow(I6), title('Contrast Decrease');

%hard threshold t=120


[m,n]=size(I1)
for i=1:m
for j=1:n
if I1(i,j)<120
I7(i,j)=0;
else
I7(i,j)=255;
end
end
end
figure, imshow(I7), title('Hard Thresholding');
OUTPUT :-

3. LAB 2
OBJECTIVE:- Gray Level Slicing without Background
INPUT CODE:-
clc
close all
clear all
%gray-level slicing without background
I3=imread('football_qcif_0000.bmp');
I4=rgb2gray(I3);
I5=double(I4);
L=double(255);
a=double(round(L/2));
b=double(round(1.5*L/2));
[m1,n1]=size(I4);

for i=1:m1
for j=1:n1
if I5(i,j)>=a & I5(i,j)<=b
I6(i,j)=L;
else
I6(i,j)=0;
end
end
end
A5=imshow(I6);

a1=double(round(L/2.5));
b1=double(round(1.8*L/2));
[m1,n1]=size(I4);

for i=1:m1
for j=1:n1
if I5(i,j)>=a1 & I5(i,j)<=b1
I7(i,j)=L;
else
I7(i,j)=0;
end
end
end
A4=imshow(I7);
A3=imshow(I5);
A2=imshow(I4);

a=double(round(L/2));
b=double(round(1.5*L/2));
[m1,n1]=size(I4);

for i=1:m1
for j=1:n1
if I5(i,j)>=a & I5(i,j)<=b
I8(i,j)=L;
else
I8(i,j)=0;
end
end
end
subplot(231), imshow(I3),title('Original');
subplot(232), imshow(I4),title('Gray Scale');
subplot(233), imshow(I6),title('I1');
subplot(234), imshow(I7),title('I2');
subplot(235), imshow(I8),title('I3');

OUTPUT:-

4. LAB 3 :-
OBJECTIVE:- Gray level slicing, Logarithmic and Inverse logarithmic transformations
and Gamma Corrections

INPUT CODE:-
clc;
close all;
clear all;

I4=imread('flowers.jpg');
I4=rgb2gray(I4);
I5=double(I4);
L=double(255);
a=double(round(L/2));
% a1=double(round(L/3));
a1=180;
b=double(round(1.5*L/2));
% b1=double(round(2.5*L/2));
b1=200;
[m1,n1]=size(I4);
for i=1:m1
for j=1:n1
if I5(i,j)>=a & I5(i,j)<=b
I6(i,j)=L;
else
I6(i,j)=0;
end
end
end

for i=1:m1
for j=1:n1
if I5(i,j)>=a1 & I5(i,j)<=b1
I7(i,j)=L;
else
I7(i,j)=0;
end
end
end

for i=1:m1
for j=1:n1
if I5(i,j)>=a1 & I5(i,j)<=b1
I8(i,j)=L;
else
I8(i,j)=I5(i,j);
end
end
end

figure, subplot(221),imshow(I4), title('I4');


subplot(222),imshow(uint8(I6),[]), title('I6');
subplot(223),imshow(uint8(I7),[]), title('I7');
subplot(224),imshow(uint8(I8),[]), title('I8');

%logarithmic transformation

c=(L-1)/log(L);
I9=log(1+I5).*c;
figure, subplot(211),imshow(uint8(I9),[]), title('Logarithmic
Transformation')

%Inverse Logarithic transformation

I10=(exp(I9) .^(1/c))-1;
subplot(212),imshow(uint8(I10),[]), title('Inverse logarithmic
transform')

%Gamma Correction
gamma1=1.1;
gamma2=0.7;
I11=(I5).^gamma1;
I12=(I5).^gamma2;

figure, subplot(121),imshow(uint8(I11),[]), title('Gamma


Correction[1.1]');
subplot(122),imshow(uint8(I12),[]), title('Gamma
Correction[0.7]');

OUTPUT:-
5. LAB 4
OBJECTIVE:- Salt and Pepper noise adding, Using filter.
INPUT CODE:-
clc
clear all
close all
I=imread('cameraman.tif');
subplot(221), imshow(I), title('Original Image');
%add noise
I2= imnoise(I,'salt & pepper',0.2);
subplot(222), imshow(uint8(I2),[]), title('Salt and Pepper
Noise');
[n m]=size(I2);
b=[zeros(1,m);I2;zeros(1,m)];
c=b';
c=[zeros(1,m+2);c;zeros(1,m+2)];
b=c';
d=zeros(size(b));
for i=1:n
for j=1:m
P=b(i:i+2,j:j+2);
P1=P(:);
Q=zeros(9,1);
Q=sort(P1);
med=Q(5);
d(i+1,j+1)=med;
end
end
I_filt1=d(2:end-1,2:end-1);
%plot the filtered image
subplot(223), imshow(uint8(I_filt1),[]), title('Filter 1');

%using inbuilt function


I_filt2=medfilt2(I2,[3 3]);
subplot(224), imshow(uint8(I_filt2),[]), title('Filter 2');
OUTPUT :-

6. LAB 5 :-
OBJECTIVE :-
INPUT CODE:-
% expt 1:-edge detection
clc
clear all
close all
I=imread('lena.tif');
I=rgb2gray(I);
edge11=zeros(size(I));
%figure, imshow(uint8(I2),[]);
[n m]=size(I);

b=zeros(m+2,n+2);
b(2:end-1,2:end-1)=I;
dx=zeros(size(b));
dy=zeros(size(b));
lx=zeros(size(b));
sobx=[-1 -2 -1;0 0 0;1 2 1];
soby=[-1 0 1;-2 0 2;-1 0 1];
lap=[-1 -1 -1;-1 8 -1;-1 -1 -1];
lap1=[0 1 0;1 -4 1;0 1 0];
Th=80;
for i=1:n
for j=1:m
P=b(i:i+2,j:j+2);
P=double(P);
for k=1:3
for l=1:3
P1x=P.*sobx;
end
end
s=sum(P1x(:));
dx(i+1,j+1)=s;
end
end
dx=dx(2:end-1,2:end-1);
for i=1:n
for j=1:m
Q=b(i:i+2,j:j+2);
Q=double(Q)
for k=1:3
for l=1:3
Q1y=Q.*soby;
end
end
s=sum(Q1y(:));
dy(i+1,j+1)=s;
end
end
dy=dy(2:end-1,2:end-1);
delI=abs(dx)+abs(dy);
delI=abs(delI);
for i=1:n
for j=1:m
if delI(i,j)>=Th
edge11(i,j)=1;
else
edge(i,j)=0;
end
end
end
figure,imshow(uint8(edge11),[]), title('Edge Detected image');
OUTPUT:-

7. LAB 6 :-
OBJECTIVE:-
INPUT CODE:-
clc
clear all
close all
I=imread('lena.tif');
I=rgb2gray(I);
X=fft2(I);
subplot(221),imshow(X), title('Fourier Transform')
Y=ifft2(X);
subplot(222),imshow(Y,[]), title('Inverse fourier
transform');
X1=X;
X1(400:512,400:512)=0;
Y1=ifft2(X1);
subplot(223), imshow(Y1,[]), title('filtered fourier
transform');
I1=I;
I1(400:512,400:512)=0;
subplot(224), imshow(I1,[]), title('filtered image');
dctmtx(8)

OUTPUT:-

You might also like