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

Dip Lab Report

The digital image processing lab report summarizes programs for fundamental image processing techniques and noise addition. It includes programs to take input images, display and get image size, convert to binary, add, subtract, multiply and divide constants, compute differences, perform gamma correction, logarithmic and contrast stretching transformations, histogram equalization, bit plane slicing, and add salt & pepper, Poisson, and Gaussian noise. Frequency domain processing including the discrete Fourier transform and filtering are also mentioned.

Uploaded by

fawadnuml1
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
216 views

Dip Lab Report

The digital image processing lab report summarizes programs for fundamental image processing techniques and noise addition. It includes programs to take input images, display and get image size, convert to binary, add, subtract, multiply and divide constants, compute differences, perform gamma correction, logarithmic and contrast stretching transformations, histogram equalization, bit plane slicing, and add salt & pepper, Poisson, and Gaussian noise. Frequency domain processing including the discrete Fourier transform and filtering are also mentioned.

Uploaded by

fawadnuml1
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Lab report:

Subject:
Digital image processing

Submitted to:
Sir Sami

Submitted by:
Fawad
(9597)

National University of Modern Languages Islamabad


Date: 23 November 2010
Contents
1 Contents...............................................................................................................................................2
2 Fundamentals of digital image processing...........................................................................................3
2.1 Program 1: How to take input image using matlab......................................................................3
2.2 Program 2: how to display image in matlab.................................................................................3
2.3 Program 3: How to show the size of image.................................................................................4
2.4 Program 4: conversion of intensity image into binary image.......................................................4
2.5 Program 5: Adding a constant to an image..................................................................................5
2.6 Program: subtracting a constant of an image...............................................................................5
2.7 Program: multiplying a constant to an image...............................................................................6
2.8 Program: dividing an image to a constant....................................................................................7
2.9 Program: compute absolute difference of the two images............................................................8
3 Intensity transformation and special filtering.......................................................................................9
3.1 Program: Gama correction of an image where GAMA > 1..........................................................9
3.2 Program: Gama correction of an image where GAMA < 1........................................................10
3.3 Program: logarithmic and contrast stretching Transformations..................................................11
3.4 Program: Histogram of an image...............................................................................................12
3.5 Program: Histogram equalization 1...........................................................................................12
3.6 Program: Histogram equalization or contrast stretching............................................................13
3.7 Program: bit plane slicing..........................................................................................................14
3.8 Program: Image noises...............................................................................................................18
3.8.1 Noise types........................................................................................................................18
3.9 Program: Special filtering..........................................................................................................21
3.9.1 Program: linear special filtering.........................................................................................21
3.9.2 Program: Non linear special filtering.................................................................................23
Chapter # 4................................................................................................................................................24
4 Frequency domain processing...........................................................................................................24
4.1 DFT of an image.........................................................................................................................24
4.2 Filtering in frequency domain....................................................................................................24
DIP LAB REPORT
Chapter # 2

1 Fundamentals of digital image processing


1.1 Program 1: How to take input image using matlab
clear all ; close all
pic = imread('j:\pic.jpg')

1.2 Program 2: how to display image in matlab


clear all ; close all
pic = imread('j:\pic.jpg')
imshow(pic)

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

1.4 Program 4: conversion of intensity image into binary image


clear all ; close all
pic = imread('j:\pic.jpg')
imshow(pic)
whos pic
B = logical(pic)

1.5 Program 5: Adding a constant to an image


clear all ; close all
pic = imread('j:\pic.jpg')
imshow(pic)
whos pic
w = imadd(pic,156)
imshow(w)

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

1.7 Program: multiplying a constant to an image


clear all ; close all
pic = imread('j:\pic.jpg')
imshow(pic)
whos pic
w = immultiply(pic,4)
imshow(w)
Output
1.8 Program: dividing an image to a constant
clear all ; close all
pic = imread('j:\pic.jpg')
imshow(pic)
whos pic
w = imdivide(pic,4)
imshow(w)

Output

1.9 Program: compute absolute difference of the two images


clear all ; close all
pic = imread('j:\pic.jpg')
imshow(pic)
whos pic
w = imadd(pic,156)
dif = imabsdiff(w,pic)
imshow(dif)
Output

=
Chapter # 3

2 Intensity transformation and special filtering


2.1 Program: Gama correction of an image where GAMA > 1
clear all ; close all
pic = imread('j:\pic.jpg')
imshow(pic)
whos pic
w = imadd(pic,100)
figure(1)
imshow(w)
x =imadjust(w,[0.1;0.9],[0.1;0.9],5)
figure(2)
imshow(x)

Output
Before -------------- After correction
2.2 Program: Gama correction of an image where GAMA < 1

clear all ; close all


pic = imread('j:\pic.jpg')
imshow(pic)
whos pic
w = imsubtract(pic,80)
figure(1)
imshow(w)
x =imadjust(w,[0.1;0.9],[0.1;0.9],0.2)
figure(2)
imshow(x)

Output

Before -------------- After correction


2.3 Program: logarithmic and contrast stretching Transformations

clear all ; close all


pic = imread('j:\pic.jpg')
imshow(pic)
whos pic
w = imsubtract(pic,80)
figure(1)
imshow(w)
c = 0.2
x =c*log(1+double(w))
figure(2)
imshow(x)

Output

Before -------------- After correction


2.4 Program: Histogram of an image
clear all ; close all
pic = imread('j:\pic.jpg')
pic = imsubtract(pic,60)
whos pic
pic = pic(:,:,1)
subplot(1,2,1)
imshow(pic)
subplot(1,2,2)
imhist(pic)

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

2.8.1.4 Speckle noise


Coding
I = imread('j:\pic.tif');
[a b] = size(I)
J = imnoise(I,'speckle');
figure, imshow(I)
figure, imshow(J)

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

3 Frequency domain processing


3.1 DFT of an image
Coding
I = imread('j:\pic.png');
subplot(1,2,1)
I = I(:,:,1)
imshow(I)
Xlabel('Image')
s = fft2(I)
S = abs(s)
subplot(1,2,2)
imshow(S,[])
xlabel('DFT')

Plot

You might also like