Sunteți pe pagina 1din 11

RAJALAKSHMI ENGINEERING COLLEGE

CHENNAI
DEPARTMENT OF BIOMEDICAL ENGINEERING

LAB MANUAL

DIGITAL IMAGE PROCESSING LAB


BM2406

VII SEMESTER 2008-2012 BATCH

Staff incharge

Kalpana R. Associate professor


Nithya A.N.N., Lecturer

List of Experiments

1. Display of Grayscale Images.


2. Histogram Equalization.
3. Non-linear Filtering.
4. Edge detection using Operators.
5. 2-D DFT and DCT.
6. Filtering in frequency domain.
7. Display of color images.
8. conversion between color spaces.
9. DWT of images.
10. Segmentation using watershed transform.

REFERENCE:
1. Rafael C. Gonzalez, Richard E. Woods, Steven Eddins,' Digital Image Processing
using MATLAB', Pearson Education, Inc., 2004.

LIST OF EQUIPMENTS:
Computer, Software MATLAB

Experiment No.1

Display of Gray scale Images.

Aim:
To display the Gray scale images.

Apparatus Required:
Computer,Matlab Software

Syntax
imshow(I)
imshow(I,[low high])
imshow(RGB)
imshow(BW)
imshow(X,map)
imshow(filename)
himage = imshow(...)
imshow(..., param1, val1, param2, val2,...)

Theory:
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 first element specifying the intensity of
red light, the second green, and the third blue. Color intensity can be specified on
the interval 0.0 to 1.0.
imshow(filename) displays the image stored in the graphics file filename. The
file must contain an image that can be read by imread or dicomread. imshow calls
imread or dicomread to read the image from the file, but does not store the image
data in the MATLAB workspace. If the file contains multiple images, imshow
displays the first image in the file. The file 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.jpg');
image2=rgb2gray (image1);
[r c d]=size (image1);
z=zeros(r,c);
tempr=image1;
tempr(:,:,2)=z;
tempr(:,:,3)=z;
imshow(tempr)
tempg=image1;
tempg(:,:,1)=z;
tempg(:,:,3)=z;
imshow(tempg)
tempb=image1;
tempb(:,:,1)=z;
tempb(:,:,2)=z;

imshow(tempb)
Result:
Thus the gray scale image is displayed.

Experiment No.2

Histogram Equalization.

Aim:
To enhance contrast using Histogram Equalization.

Apparatus Required:
Computer,Matlab Software

Syntax
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,...)

Theory
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 specified 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 flat. (The histogram of
J is flatter 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 flat. 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)
figure, imshow(J)

Display a histogram of the original image.


figure; imhist(I,64)

Compare it to a histogram of the processed image.


figure; 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 flat hgram,
hgram = ones(1,n)*prod(size(A))/n;
Result
The histogram equalization is done.

Experiment No.3

Edge detection using Operators.

Aim:
To detect the edge of the Gray scale images.

Apparatus Required:
Computer, Matlab Software

Syntax
To demonstrate edge detection
% numbers of colors
sncols=128;
ncols=32;
% get image from MATLAB image
load('trees');
% show original image
figure(1);
showgimg(real(X),sncols);
drawnow;
% construct convolution functions
[m,n] = size(X);
gs = [1 -1]; ge = [];
hs = [1 -1]; he = [];
g = [gs,zeros(1,m-length(gs)-length(ge)),ge];
h = [hs,zeros(1,n-length(hs)-length(he)),he];
% construct convolution matrices as sparse matrices
Y = spcnvmat(g);
Z = spcnvmat(h);

Wg = Y*X;
Wh = X*Z';
% show transformed images
figure(2);
showgimg(Wg,ncols);
drawnow;
figure(3)
showgimg(Wh,ncols);
drawnow;
figure(4)
showgimg(abs(Wg)+abs(Wh),ncols);
drawnow;

Theory
Edges characterize boundaries and are therefore a problem of fundamental importance in
image processing. Edges in images are areas with strong intensity contrasts a jump in
intensity from one pixel to the next. Edge detecting an image significantly reduces the
amount of data and filters out useless information, while preserving the important structural
properties in an image. There are many ways to perform edge detection. However, the
majority of different methods may be grouped into two categories, gradient and Laplacian.
The gradient method detects the edges by looking for the maximum and minimum in the first
derivative of the image. The Laplacian method searches for zero crossings in the second
derivative of the image to find edges. An edge has the one-dimensional shape of a ramp and
calculating the derivative of the image can highlight its location. Suppose we have the
following signal, with an edge shown by the jump in intensity below: The intensity changes
thus discovered in each of the channels are then represented by oriented primitives called
zero-crossing segments, and evidence is given that this representation is complete. (2)
Intensity changes in images arise from surface discontinuities or from reflectance or
illumination boundaries, and these all have the property that they are spatially localized.
Because of this, the zero-crossing segments from the different channels are not independent,
and rules are deduced for combining them into a description of the image. This description is
called the raw primal sketch.

Result
The edge detection of the image is done.

S-ar putea să vă placă și