Dip Lab Report
Dip Lab Report
Subject:
Digital image processing
Submitted to:
Sir Sami
Submitted by:
Fawad
(9597)
Output file
1.3 Program 3: How to show the size of image
clear all ; close all
pic = imread('j:\pic.jpg')
imshow(pic)
whos pic
Output
Name Size Bytes Class Attributes
pic 293x341x3 299739 uint8
Output
1.6 Program: subtracting a constant of an image
clear all ; close all
pic = imread('j:\pic.jpg')
imshow(pic)
whos pic
w = imsubtract(pic,156)
imshow(w)
Output
Output
=
Chapter # 3
Output
Before -------------- After correction
2.2 Program: Gama correction of an image where GAMA < 1
Output
Output
Output
2.5 Program: Histogram equalization 1
clear all ; close all
pic = imread('j:\pic.jpg')
pic = imsubtract(pic,60)
whos pic
subplot(2,2,1)
pic = pic(:,:,1)
imshow(pic)
subplot(2,2,2)
imhist(pic)
c = 0.16
x =c*log(1+double(pic))
subplot(2,2,3)
imshow(x)
subplot(2,2,4)
imhist(x)
Output
2.6 Program: Histogram equalization or contrast stretching
clear all ; close all
pic = imread('j:\pic.png')
pic = imsubtract(pic,60)
whos pic
subplot(2,2,1)
pic = pic(:,:,1)
imshow(pic)
subplot(2,2,2)
imhist(pic)
c = 0.16
A = histeq(pic)
A = A(:,:,1)
subplot(2,2,3)
imshow(A)
subplot(2,2,4)
imhist(A)
Output
2.7 Program: bit plane slicing
Coding
clear all; close all; clc;
f = imread('j:\pic.tif');
figure,imshow(f);
[m n] = size(f);
c = cell(1,8);
for i = 1:m
for j = 1:n
b = f(i,j);
if ( b >= 128)
b = b-128; c{1,1}(i,j) = 1;
else
c{1,1}(i,j) = 0;
end
if (b >= 64)
b = b - 64; c{1,2}(i,j) = 1;
else
c{1,2}(i,j) = 0;
end
if (b >= 32)
b = b - 32; c{1,3}(i,j) = 1;
else
c{1,3}(i,j) = 0;
end
if (b >= 16)
b = b - 16; c{1,4}(i,j) = 1;
else
c{1,4}(i,j) = 0;
end
if (b >= 8)
b = b - 8; c{1,5}(i,j) = 1;
else
c{1,5}(i,j) = 0;
end
if (b >= 4)
b = b - 4; c{1,6}(i,j) = 1;
else
c{1,6}(i,j) = 0;
end
if (b >= 2)
b = b - 2; c{1,7}(i,j) = 1;
else
c{1,3}(i,j) = 0;
end
if (b >= 1)
b = b - 1; c{1,8}(i,j) = 1;
else
c{1,8}(i,j) = 0;
end
end
end
f1 = c{1,1}; f2 = c{1,2}; f3 = c{1,3}; f4 = c{1,4};
f5 = c{1,5}; f6 = c{1,6}; f7 = c{1,7}; f8 = c{1,8};
subplot(8,1,1),imshow(f1),title('Bit-Plane 0');
subplot(8,1,2),imshow(f2),title('Bit-Plane 1');
subplot(8,1,3),imshow(f3),title('Bit-Plane 2');
subplot(8,1,4),imshow(f4),title('Bit-Plane 3');
subplot(8,1,5),imshow(f5),title('Bit-Plane 4');
subplot(8,1,6),imshow(f6),title('Bit-Plane 5');
subplot(8,1,7),imshow(f7),title('Bit-Plane 6');
subplot(8,1,8),imshow(f8),title('Bit-Plane 7');
Plot
2.8 Program: Image noises
2.8.1 Noise types
2.8.1.1 Salt & pepper
Coding
I = imread('j:\pic.tif');
J = imnoise(I,'salt & pepper',0.02);
figure, imshow(I)
figure, imshow(J)
Plot
Original ------------------------------------------------------------------ salt and pepper
2.8.1.2 Poisson noise
Coding
I = imread('j:\pic.tif');
[a b] = size(I)
J = imnoise(I,'poisson');
figure, imshow(I)
figure, imshow(J)
Plot
Original ------------------------------------------------------------------ poisson
2.8.1.3 Gaussian
Coding
I = imread('j:\pic.tif');
J = imnoise(I,'gaussian');
figure, imshow(I)
figure, imshow(J)
Plots
Original ------------------------------------------------------------------ Gaussian noise
Plot
Original ------------------------------------------------------------------ Gaussian noise
2.9 Program: Special filtering
2.9.1 Program: linear special filtering
2.9.1.1 Program: linear special filtering through convolution
Coding
I = imread('j:\Ches.gif');
J = imnoise(I,'salt & pepper',0.2);
subplot(1,2,1), imshow(J)
Xlabel('noisy image')
J= double(J)
w = ones(12,12)
g=imfilter(J,w,'conv')
subplot(1,2,2)
imshow(g,[])
xlabel('filtered')
Plot
2.9.1.2 Program: linear special filtering through correlation
Coding
I = imread('j:\Ches.gif');
J = imnoise(I,'salt & pepper',0.2);
subplot(1,2,1), imshow(J)
Xlabel('noisy image')
J= double(J)
w = ones(12,12)
g=imfilter(J,w,'corr')
subplot(1,2,2)
imshow(g,[])
xlabel('filtered')
Plot
2.9.2 Program: Non linear special filtering
2.9.2.1 Program: Median filter
Coding
I = imread('j:\Ches.gif');
J = imnoise(I,'salt & pepper',0.2);
subplot(1,2,1), imshow(J)
Xlabel('noisy image')
J= double(J)
w = ones(12,12)
g=medfilt2(J,[3,3],'symmetric')
subplot(1,2,2)
imshow(g,[])
xlabel('filtered')
Plot
Chapter # 4
Plot