Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 11

RAJALAKSHMI ENGINEERING COLLEGE

CHENNAI
DEPARTMENT OF BIOMEDICAL ENGINEERING
LAB MANUAL
DIGITAL IMAGE PROCESSING LAB
BM2406
VII SEMESTER 2008-2012 BATCH
Staff i!"a#$%
&a'(aa R) A**+!iat% (#+f%**+#
Nit",a A)N)N)- L%!t.#%#
List of Experiments
1. Display of Grayscale Images.
2. Histogram Equalization.
3. Non-linear Filtering.
. E!ge !etection using "perators.
#. 2-D DF$ an! D%$.
&. Filtering in frequency !omain.
'. Display of color images.
(. con)ersion *et+een color spaces.
,. D-$ of images.
1.. /egmentation using +aters0e! transform.
REFERENCE/
1. 1afael %. Gonzalez2 1ic0ar! E. -oo!s2 /te)en E!!ins23 Digital Image 4rocessing
using 56$76832 4earson E!ucation2 Inc.2 2...
LIST OF E0UIPMENTS/
%omputer2 /oft+are 56$768
E1(%#i2%t N+)1 Di*('a, +f G#a, *!a'% I2a$%*)
Ai2/
To display the Gray scale images.
A((a#at.* R%3.i#%4/
Computer,Matlab Software
S,ta1
imshow(I)
imshow(I,[low high])
imshow(RGB)
imshow(BW)
imshow(X,map)
imshow(flename)
himage = imshow(...)
imshow(..., param1, val1, param2, val2,...)
T"%+#,/
imshow(I) displays the grayscale image I.
imshow(I,[low high]) displays the grayscale image I, specifying the display
range for I in [low high]. The value low (and any value less than low) displays as
black; the value high (and any value greater than high) displays as white. Values in
between are displayed as intermediate shades of gray, using the default number of
gray levels. If you use an empty matrix ([]) for [low high], imshow uses [min(I(:))
max(I(:))]; that is, the minimum value in I is displayed as black, and the maximum
value is displayed as white.
imshow(RGB) displays the truecolor image RGB.
imshow(BW) displays the binary image BW. imshow displays pixels with the
value 0 (zero) as black and pixels with the value 1 as white.
imshow(X,map) displays the indexed image X with the colormap map. A color
map matrix may have any number of rows, but it must have exactly 3 columns.
Each row is interpreted as a color, with the frst element specifying the intensity of
red light, the second green, and the third blue. Color intensity can be specifed on
the interval 0.0 to 1.0.
imshow(flename) displays the image stored in the graphics fle flename. The
fle must contain an image that can be read by imread or dicomread. imshow calls
imread or dicomread to read the image from the fle, but does not store the image
data in the MATLAB workspace. If the fle contains multiple images, imshow
displays the frst image in the fle. The fle must be in the current directory or on
the MATLAB path.
himage = imshow(...) returns the handle to the image object created by imshow.
imshow(..., param1, val1, param2, val2,...) displays the image, specifying
parameters and corresponding values that control various aspects of the image
display.
Converting RGB Image into gray scale image & extracting the color
Spaces
image1=imread('dse_college!pg'"#
image$=rg%$gray (image1"#
&r c d'=si(e (image1"#
(=(eros(r)c"#
tempr=image1#
tempr(*)*)$"=(#
tempr(*)*)+"=(#
imsho,(tempr"
tempg=image1#
tempg(*)*)1"=(#
tempg(*)*)+"=(#
imsho,(tempg"
temp%=image1#
temp%(*)*)1"=(#
temp%(*)*)$"=(#
imsho,(temp%"
Result:
Thus the gray scale image is displayed.
E1(%#i2%t N+)2 Hi*t+$#a2 E3.a'i5ati+)
Ai2/
To enhance contrast using Histogram Equalization.
A((a#at.* R%3.i#%4/
Computer,Matlab Software
S,ta1
J = histeq(I, hgram)
J = histeq(I, n)
[J, T] = histeq(I,...)
newmap = histeq(X, map, hgram)
newmap = histeq(X, map)
[newmap, T] = histeq(X,...)
T"%+#,
histeq enhances the contrast of images by transforming the values in an intensity
image, or the values in the colormap of an indexed image, so that the histogram of
the output image approximately matches a specifed histogram.
J = histeq(I, hgram) transforms the intensity image I so that the histogram of the
output intensity image J with length(hgram) bins approximately matches hgram.
histeq automatically scales hgram so that sum(hgram) = prod(size(I)). The
histogram of J will better match hgram when length(hgram) is much smaller than
the number of discrete levels in I.
J = histeq(I, n) transforms the intensity image I, returning in J an intensity image
with n discrete gray levels. A roughly equal number of pixels is mapped to each of
the n levels in J, so that the histogram of J is approximately fat. (The histogram of
J is fatter when n is much smaller than the number of discrete levels in I.) The
default value for n is 64.
[J, T] = histeq(I,...) returns the grayscale transformation that maps gray levels in
the image I to gray levels in J.
newmap = histeq(X, map, hgram) transforms the colormap associated with the
indexed image X so that the histogram of the gray component of the indexed image
(X,newmap) approximately matches hgram. The histeq function returns the
transformed colormap in newmap. length(hgram) must be the same as size(map,1).
newmap = histeq(X, map) transforms the values in the colormap so that the
histogram of the gray component of the indexed image X is approximately fat. It
returns the transformed colormap in newmap.
[newmap, T] = histeq(X,...) returns the grayscale transformation T that maps the
gray component of map to the gray component of newmap.
Examples
Enhance the contrast of an intensity image using histogram equalization.
I = imread('tire.tif');
J = histeq(I);
imshow(I)
fgure, imshow(J)
Display a histogram of the original image.
fgure; imhist(I,64)
Compare it to a histogram of the processed image.
fgure; imhist(J,64)
Algorithm
When you supply a desired histogram hgram, histeq chooses the grayscale
transformation T to minimize where c0 is the cumulative histogram of A, c1 is the
cumulative sum of hgram for all intensities k. This minimization is subject to the
constraints that T must be monotonic and c1(T(a)) cannot overshoot c0(a) by more
than half the distance between the histogram counts at a. histeq uses the
transformation b = T(a) to map the gray levels in X (or the colormap) to their new
values.If you do not specify hgram, histeq creates a fat hgram,
hgram = ones(1,n)*prod(size(A))/n;
Result
The histogram equalization is done.
E1(%#i2%t N+)6 E4$% 4%t%!ti+ .*i$ O(%#at+#*)
Ai2/
To detect the edge of the Gray scale images.
A((a#at.* R%3.i#%4/
Computer, Matlab Software
S,ta1
To demonstrate edge detection
% numbers of colors
sncols=128;
ncols=32;
% get image from MATLAB image
load('trees';
% s!o" original image
figure(1;
s!o"gimg(real(#$sncols;
dra"no";
% construct con%olution functions
&m$n' = si(e(#;
gs = &1 )1'; ge = &';
!s = &1 )1'; !e = &';
g = &gs$(eros(1$m)lengt!(gs)lengt!(ge$ge';
! = &!s$(eros(1$n)lengt!(!s)lengt!(!e$!e';
% construct con%olution matrices as s*arse matrices
+ = s*cn%mat(g;
, = s*cn%mat(!;
-g = +.#;
-! = #.,';
% s!o" transformed images
figure(2;
s!o"gimg(-g$ncols;
dra"no";
figure(3
s!o"gimg(-!$ncols;
dra"no";
figure(/
s!o"gimg(abs(-g0abs(-!$ncols;
dra"no";
T"%+#,
E!ges c0aracterize *oun!aries an! are t0erefore a pro*lem of fun!amental importance in
image processing. E!ges in images are areas +it0 strong intensity contrasts 9 a :ump in
intensity from one pi;el to t0e ne;t. E!ge !etecting an image significantly re!uces t0e
amount of !ata an! filters out useless information2 +0ile preser)ing t0e important structural
properties in an image. $0ere are many +ays to perform e!ge !etection. Ho+e)er2 t0e
ma:ority of !ifferent met0o!s may *e groupe! into t+o categories2 gra!ient an! 7aplacian.
$0e gra!ient met0o! !etects t0e e!ges *y loo<ing for t0e ma;imum an! minimum in t0e first
!eri)ati)e of t0e image. $0e 7aplacian met0o! searc0es for zero crossings in t0e secon!
!eri)ati)e of t0e image to fin! e!ges. 6n e!ge 0as t0e one-!imensional s0ape of a ramp an!
calculating t0e !eri)ati)e of t0e image can 0ig0lig0t its location. /uppose +e 0a)e t0e
follo+ing signal2 +it0 an e!ge s0o+n *y t0e :ump in intensity *elo+= $0e intensity c0anges
t0us !isco)ere! in eac0 of t0e c0annels are t0en represente! *y oriente! primiti)es calle!
zero-crossing segments2 an! e)i!ence is gi)en t0at t0is representation is complete. >2?
Intensity c0anges in images arise from surface !iscontinuities or from reflectance or
illumination *oun!aries2 an! t0ese all 0a)e t0e property t0at t0ey are spatially localize!.
8ecause of t0is2 t0e zero-crossing segments from t0e !ifferent c0annels are not in!epen!ent2
an! rules are !e!uce! for com*ining t0em into a !escription of t0e image. $0is !escription is
calle! t0e ra+ primal s<etc0.

R%*.'t
The edge detection of the image is done.

You might also like