DIVP MANUAL Exp

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

LIST OF EXPERIMENTS

S.NO DATE NAME OF THE EXPERIMENT STAFF SIGNATURE


1 Basic Commands for Image Processing

2 Fourier analysis of Image

3 Image Filtering
4 Histogram Modifications

5 Image Smoothing

6 Singular Value Decomposition


7 Run Length Coding

8 Basic Edge Detection Operations

9 Revision Experiment
10 Wavelet Coding

11 JPEG Compression

12 Region Based Compression


13 Convert video into frames

14 Filtering Video Signals

15 Erosion and Dilation operations in an image


16 Color image segmentation algorithm development

17 Morphological operations in analyzing image


structures
18 Mini project: Number Plate Detection
Exp: No.1 BASIC COMMANDS FOR IMAGE PROCESSING
Date:

AIM

To provide the thresholding an image and learn the basic Commands for image
Processing.

SOFTWARE

MATLAB

THEORY

PROGRAM

1. The imread() command will read an image into a matrix:

img = imread('ImageProcessing_1/BerkeleyTower.png');
>> size(img)

ans =
499 748 3

2. imshow
To show our image, we the imshow() or imagesc() command. The imshow() command shows an image
in standard 8-bit format, like it would appear in a web browser.

The imagesc() command displays the image on scaled axes with the min value as black and the max value
as white.
subplot(131);

imagesc(img(:,:, 1))
; title('Red');

img =
imread('ImageProcessing_1/BerkeleyTower.png');
subplot(132);
imagesc(img(:,:, 2)) ;
title('Green');

subplot(133);
imagesc(img(:,:, 3))
; title('Blue');

3. Command colormap gray, the picture turns into a grayscale

>> colormap gray

4. imwrite() command, save the image

imwrite(blue_img, 'Blue4_BerkeleyTower.png', 'png');

5. rgb2gray() – Convert RGB color image into gray image

img =
imread('ImageProcessing_1/BerkeleyTower.png');
gray = rgb2gray(img);
imshow(gray);
OUTPUT - Experiment-1

Using imshow()

Figure 1.1 Image using imshow


Using imagesc()

Figure 1.2 Image using imagesc() command

Red , Green and Blue color image

Figure 1.3. Red, green and blue color image


RESULT
Thus the thresholding an image is done and the basic image processing Commands were illustrated.
Exp: No.2 FOURIER ANALYSIS OF IMAGE
Date:

AIM
To perform the Two-dimensional Fourier transform operation in an image.

SOFTWARE

MATLAB

THEORY:
The Fourier Transform is an important image processing tool which is used decompose an image
into its sine and cosine components. The output of the transformation represents the image in the Fourier
or frequency domain, while the input image is the spatial domain equivalent. In the Fourier domain
image, each point represents a particular frequency contained in the spatial domain image. The Fourier
Transform is used in a wide range of applications, such as image analysis, image filtering, image
reconstruction and image compression.

PROGRAM:

clc;
u=imread(‘C\image.jpg’ );
oip=rgb2gray(u);
figure; imshow(oip);
title(‘Gray scale Image’);
uiop=fft2(oip); figure;
imshow(uiop);
title(‘Fourier analysis image’); uyiop=ifft2(uiop);
figure;
imshow(uint8(uyiop)); title(‘Inverse
Fourier analysis image’); OUTPUT -
Experiment-2

Figure 2.1 Gray image


Figure 2.2 Encrypted Image after Applying Fourier Transform

Figure 2.3: Decrypted image After Applying Inverse of Fourier Transform

RESULT
Thus the two-dimensional Fourier transform operation in an image os performed.
Exp: No.3 IMAGE FILTERING
Date:

AIM
To perform the Linear filtering using convolution in an image.

SOFTWARE MATLAB

THEORY
Linear filtering of an image is accomplished through an operation called convolution.
Convolution is a neighborhood operation in which each output pixel is the weighted sum of neighboring
input pixels. The matrix of weights is called the convolution kernel, also known as the filter. A
convolution kernel is a correlation kernel that has been rotated 180 degrees.

For example, suppose the image is


17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
A= 11 18 25 2 9
And the convolution kernel is

816
3 5 7 h= 4 9
2
The following figure shows how to compute the (2,4) output pixel using these steps:
1. Rotate the convolution kernel 180 degrees about its center element.
2. Slide the center element of the convolution kernel so that it lies on top of the (2,4) element of A.
3. Multiply each weight in the rotated convolution kernel by the pixel of A underneath.
4. Sum the individual products from step 3.
PROGRAM
clc;
u=imread(‘c\image.jpg’);
figure; imshow(u);
title(‘original Image’); Hm=
fspecial('motion',20,45);
MotionBlur = imfilter(u,Hm,'replicate'); figure;
imshow(MotionBlur); title(‘Motion
Blurred Image’);
Hb=fspecial('disk',10);
Blurred = imfilter(u,Hb,'replicate');
figure; imshow(blurred);
title(‘Filtered Image’);

OUTPUT- Experiment-3

Figure 3.1 Image Figure 3.2 Motion blurred image

Figure 3.3 Filtered image

RESULT

Thus the Linear filtering using Convolution in an image is performed.


Exp: No.4 HISTOGRAM MODIFICATIONS
Date:

AIM

To provide the thresholding an image and the evaluation of its histogram using histogram
equalization and illustrates the relationship among the intensities (gray levels) of an image and its
histogram.

SOFTWARE
MATLAB

THEORY
Histogram is a graphical representation of the intensity distribution of an image. In simple terms,
it represents the number of pixels for each intensity value considered. Histogram Equalization is a
computer image processing technique used to improve contrast in images. It accomplishes this by
effectively spreading out the most frequent intensity values, i.e. stretching out the intensity range of the
image. This method usually increases the global contrast of images when its usable data is represented
by close contrast values. This allows for areas of lower local contrast to gain a higher contrast.

A color histogram of an image represents the number of pixels in each type of color component.
Histogram equalization cannot be applied separately to the Red, Green and Blue components of the image
as it leads to dramatic changes in the image’s color balance. However, if the image is first converted to
another color space, like HSL/HSV color space, then the algorithm can be applied to the luminance or
value channel without resulting in changes to the hue and saturation of the image.

Adaptive Histogram Equalization


Adaptive Histogram Equalization differs from ordinary histogram equalization in the respect that
the adaptive method computes several histograms, each corresponding to a distinct section of the image,
and uses them to redistribute the lightness values of the image. It is therefore suitable for improving the
local contrast and enhancing the definitions of edges in each region of an image.

Contrastive Limited Adaptive Equalization


Contrast Limited AHE (CLAHE) differs from adaptive histogram equalization in its contrast
limiting. In the case of CLAHE, the contrast limiting procedure is applied to each neighborhood from
which a transformation function is derived. CLAHE was developed to prevent the over amplification of
noise that adaptive histogram equalization can give rise to.
PROGRAM
clc;
u=imread(‘c\image.jpg’);
figure; imshow(u);
title(‘original Image’);
o=rgb2gray(u); figure
imshow(o);
title(‘Gray scale Image’);
figure; imhist(o);
title(‘Histogram before equalization’);
i=histeq(o); figure; imshow(i);
title(' Histogram after equalization’);
figure; imhist(i);
OUTPUT - Experiment-4

Figure 4.1 Gray scale image Figure 4.2 Histogram of the image

Figure 4.3 Image after applying Histogram Figure 4.4 Histogram Equalization
Equalization

RESULT
Thus thresholding an image and the evaluation of its histogram using Histogram equalization. is
illustrated using the relationship among the intensities (gray levels) of an image and its histogram.
Exp: No.5 IMAGE SMOOTHING
Date:

AIM

To perform the median filtering to smooth and remove the image

SOFTWARE

MATLAB

THEORY

The median filter is a non-linear digital filtering technique, often used to remove noise from an
image or signal. Such noise reduction is a typical pre- processing step to improve the results of later
processing (for example, edge detection on an image).

PROGRAM

clc;
I = imread('eight.tif'); figure,; imshow(I);
title(‘Original Image’);
J = imnoise(I,'salt & pepper',0.02);
K = medfilt2(J);
figure;
imshowpair(J,K,'montage');
title(‘Median Filtered Image’);
OUTPUT - Experiment-5

Figure 5.1 Input image Figure 5.2 Median filtered image

RESULT
Thus the experiment illustrates the smoothing operation using median filter.
Exp: No.6 SINGULAR VALUE DECOMPOSITION
Date:

AIM

To perform the singular value decomposition of the array

SOFTWARE

MATLAB

THEORY
Singular value decomposition expresses an m-by-n matrix A as A = U*S*V'. Here, S is an m- by-
n diagonal matrix with singular values of A on its diagonal. The columns of the m-by-m matrix U are the
left singular vectors for corresponding singular values. The columns of the n-by-n matrix V are the right
singular vectors for corresponding singular values. V' is the Hermitian transpose (the complex conjugate
of the transpose) of V.

PROGRAM
svd(A)
[U,S,V] = svd(A) n= 3; for
i = 1:n for j = 1:n A(i,j) =
sym(1/(i-j+1/2));
end end

OUTPUT - Experiment-6
2 2 2/3
2/3 2 2
For n = 3, the matrix is A = 2 / 5 2 / 3 2

S =svd(vpa(A)) S =3.1387302525015353960741348953506
3.0107425975027462353291981598225
1.6053456783345441725883965978052
U = [ 0.53254331027335338470683368360204, 0.76576895948802052989304092179952,...
0.36054891952096214791189887728353]
[ -0.82525689650849463222502853672224, 0.37514965283965451993171338605042,...
0.42215375485651489522488031917364]
[ 0.18801243961043281839917114171742, -0.52236064041897439447429784257224,...
0.83173955292075192178421874331406]
S = [ 3.1387302525015353960741348953506, 0,...0]
[ 0, 3.0107425975027462353291981598225,...0]
[ 0, 0,...1.6053456783345441725883965978052]
V =[ 0.18801243961043281839917114171742, 0.52236064041897439447429784257224,...
0.83173955292075192178421874331406]
[ -0.82525689650849463222502853672224, -0.37514965283965451993171338605042,...
0.42215375485651489522488031917364]
[ 0.53254331027335338470683368360204, -0.76576895948802052989304092179952,...
0.36054891952096214791189887728353]

RESULT
Thus the experiment performs the Singular Value Decomposition of the array.
Exp: No.7 RUN LENGTH CODING
Date:

AIM

To perform the Run length encoding and decoding process

SOFTWARE

MATLAB

THEORY

Run-length encoding (RLE) is a form of lossless data compression in which runs of data
(sequences in which the same data value occurs in many consecutive data elements) are stored as a single
data value and count, rather than as the original run.

PROGRAM
function data = rle(x) if
iscell(x)
i= cumsum([1x{2}]);
j=zeros(1,i(end)-1);
j(i(1:end-1)) = 1; data
=x{1}(cumsum(j));
else if
size(x,1)>size(x,2),x=x';
end i = [ find(x(1:end-1) ~=
x(2:end)) length(x) ]; data{2} = diff([ 0 i]);
data{1} = x(i); end

RESULT

Thus the run length encoding and decoding is performed.


Exp: No.8 BASIC EDGE DETECTION OPERATIONS
Date:

AIM
To perform the Image Edge Detection Using Sobel Filtering and Canny Filtering.

SOFTWARE
MATLAB

THEORY

Edge detection is an image processing technique for finding the boundaries of objects within
images. It works by detecting discontinuities in brightness. Edge detection is used for image segmentation
and data extraction in areas such as image processing, computer vision, and machine vision. Common
edge detection algorithms include Sobel, Canny, Prewitt, Roberts, and fuzzy logic methods.
Edge detection method, specified as one of the following.

Method Descripti on

'Sobel' Finds edges at those points where the gradient of the image I is maximum, using the
Sobel approximation to the derivative.

'Prewitt' Finds edges at those points where the gradient of I is maximum, using the
Prewitt approximation to the derivative.

'Roberts' Finds edges at those points where the gradient of I is maximum, using the
Roberts approximation to the derivative.

'log' Finds edges by looking for zero-crossings after filtering I with a Laplacian of
Gaussian (LoG) filter.

'zerocross' Finds edges by looking for zero-crossings after filtering I with a filter that you
specify, h
'Canny' Finds edges by looking for local maxima of the gradient of I. The edge function calculates
the gradient using the derivative of a Gaussian filter. This method uses two thresholds to
detect strong and weak edges, including weak edges in the output if they are connected
to strong edges. By using two thresholds, the Canny method is less likely than the other
methods to be fooled by noise, and more likely to detect true weak edges.

'approxcanny' Finds edges using an approximate version of the Canny edge detection algorithm that
provides faster execution time at the expense of less precise detection. Floating point
images are expected to be normalized in the range [0 1].

PROGRAM
clc;
I = imread('circuit.tif'); imshow(I)
BW1 = edge(I,'Canny'); BW2 =
edge(I,'Prewitt');
imshowpair(BW1,BW2,'montage')
.

Output -- Experiment-8

Figure 8.1 Input image Figure 8.2 Edge detected

Result
Thus the Image Edge Detection Using Prewitts Filtering and Canny Filtering is performed.
Exp: No.9 REVISION EXPERIMENTS
Date:

AIM
To perform the image rotation, scaling, and translation using Geometric transformation function.

SOFTWARE

MATLAB

THEORY
Perform generic geometric transformations using the imwarp workflow. Geometric
transformations map pixel coordinates in the output image to coordinates in the input image. The
mapping process then interpolates the value of output pixels from the input image. Use these functions
to perform general 2-D, 3-D, and N-D geometric transformations. To perform a 2-D or 3- D geometric
transformation, first create a geometric transformation object that stores information about the
transformation. Then, pass the image to be transformed and the geometric transformation object to the
imwarp function.

imwarp Apply geometric transformation to image

affineOutputView Create output view for warping images

fitgeotrans Fit geometric transformation to control point pairs

findbounds Find output bounds for spatial transformation

fliptform Flip input and output roles of spatial transformation structure

makeresampler Create resampling structure

maketform Create spatial transformation structure (TFORM)

tformarray Apply spatial transformation to N-D array

tformfwd Apply forward spatial transformation

tforminv Apply inverse spatial transformation


PROGRAM
Image Scaling-1
I = imread('rice.png');
J = imresize(I, 0.5);
figure; imshow(I);
title('Original Image');
figure; imshow(J) ;
title('Resized Image');
Image Scaling-2
I = imread('rice.png'); J =
imresize(I, [256 256]);
figure; imshow(I);
title('Original Image');
figure; imshow(J);
title('Resized Image');
Image Scaling-3
I = imread('rice.png');
J=imresize(I,0.5,'nearest')
; figure; imshow(I);
title('Original Image')
figure; imshow(J);
title('ResizedImageUsingNearest-Neighbor');
I = imread('cameraman.tif');
figure; imshow(I);
title('Original Image'); J=
imtranslate(I,[15, 25]);
figure; imshow(J);
title('Translated Image');
K=imtranslate(I,[15,25],'OutputView','full'); figure;
imshow(K);
title('Translated Image, Unclipped')
RGB to HSV
Ima=imread('board.tif');
Imshow(Ima)
Hsv-Im=rgb2hsv(Ima); Imshow(Hsv-Im);
HSV to RGB
RGB=hsv2rgb(HSV-Im)

RESULT:
Thus the operation on digital image and image rotation, scaling, and translation using Geometric
transformations is performed.
Exp: No.10 WAVELET CODING
Date:

AIM
To perform the Discrete Wavelet transform of the image.

SOFTWARE
MATLAB

THEORY

DWT algorithms have become standard tools for discrete signal and image processing in several
areas in research and industry. DWT provides both frequency time signal and location information of the
analyzed signal.

PROGRAM
clc;
i=imread('image22.jpg'); sX=size(i);
[LL,LH,HL,HH]=dwt2(i,'db1');
figure(1); subplot(2,2,1);
imshow(LL);
title('LLbandofimage');
subplot(2,2,2);
imshow(LH);
title('LHbandofimage');
subplot(2,2,3);
imshow(HL);
title('HLbandofimage');
subplot(2,2,4);
imshow(HH);
title('HHbandofimage');
X =idwt2(LL,LH,HL,HH,'db1',sX);
figure(2) imshow(X);

RESULT
Thus Discrete Wavelet transform of the image is performed.
Exp: No.11 JPEG COMPRESSION
Date:

AIM

To perform compression of image using JPEG

SOFTWARE

MATLAB

THEORY
It is a commonly used method of lossy compression for digital images, particularly for those
images produced by digital photography. The degree of compression can be adjusted, allowing a
selectable trade-off between storage size and image quality. JPEG typically achieves 10:1 compression
with little perceptible loss in image quality.[3] Since its introduction in 1992, JPEG has been the most
widely used image compression standard in the world,[4][5] and the most widely used digital image format,
with several billion JPEG images produced every day as of 2015

Program
clc; clear all;
I = imread('cameraman.tif'); I1=I;
[row coln]=size(I); I= double(I);
I = I -(128*ones(256)); quality = input('What quality of
compression you require - ');
Q50=[ 16 11 10 16 24 40 51 61;
12 12 14 19 26 58 60 55;
14 13 16 24 40 57 69 56;
14 17 22 29 51 87 80 62;
18 22 37 56 68 109 103 77;
24 35 55 64 81 104 113 92;
49 64 78 87 103 121 120 101;
72 92 95 98 112 100 103 99]; if
quality > 50
QX = round(Q50.*(ones(8)*((100-quality)/50)));
QX = uint8(QX); elseifquality<50
QX = round(Q50.*(ones(8)*(50/quality))); QX = uint8(QX);
elseifquality==50 QX = Q50; end
DCT_matrix8 = dct(eye(8)); iDCT_matrix8
= DCT_matrix8'; dct_restored =
zeros(row,coln);
QX = double(QX); for
i1=[1:8:row] for
i2=[1:8:coln]
zBLOCK=I(i1:i1+7,i2
:i2+7);
win1=DCT_matrix8*zBLOCK*iDCT_matrix8;
dct_domain(i1:i1+7,i2:i2+7)=win1; end
end for i1=[1:8:row] for i2=[1:8:coln] win1 =
dct_domain(i1:i1+7,i2:i2+7);
win2=round(win1./QX);
dct_quantized(i1:i1+7,i2:i2+7)=win2;
end
end for
i1=[1:8:row] for
i2=[1:8:coln]
win2 =
dct_quantized(i1:i1+7,i2:i2+7);
win3 = win2.*QX;
dct_dequantized(i1:i1+7,i2:i2+7) =
win3;
end
end for
i1=[1:8:row] for
i2=[1:8:coln]
win3 = dct_dequantized(i1:i1+7,i2:i2+7);
win4=iDCT_matrix8*win3*DCT_matrix8; dct_restored(i1:i1+7,i2:i2+7)=win4;
end
endI2=dct_restored;
K=mat2gray(I2);
figure(1); imshow(I1);

title('original image'); figure(2); imshow(K);


title('restoredimagefromdct');

RESULT

Thus the compression of image using JPEG is performed


Exp: No.12 REGION BASED COMPRESSION
Date:

AIM
To perform the segmentation of image using region growing

SOFTWARE MATLAB

THEORY

Region growing is a simple region-based image segmentation method. ... This approach to
segmentation examines neighboring pixels of initial seed points and determines whether the pixel
neighbors should be added to the region. The process is iterated on, in the same manner as general data
clustering algorithms.

PROGRAM

if(exist('reg_maxdist','var')==0), reg_maxdist=0.2; end


if(exist('y','var')==0),figure,imshow(I,[]);
[y,x]=getpts;y=round(y(1)); x=round(x(1)); end
J = zeros(size(I));
Isizes = size(I);
reg_mean=I(x,y);
reg_size = 1; neg_free
= 10000; neg_pos=0;
neg_list = zeros(neg_free,3); pixdist=0;
neigb=[-1 0; 1 0; 0 -1;0 1];
while(pixdist<reg_maxdist&&reg_size<numel(I)) for
j=1:4,
xn = x +neigb(j,1); yn = y +neigb(j,2);
ins=(xn>=1)&&(yn>=1)&&(xn<=Isizes(1))&&(yn<=Isizes();
if(ins&&(J(xn,yn)==0)) neg_pos = neg_pos+1;
neg_list(neg_pos,:) = [xn yn I(xn,yn)]; J(xn,yn)=1;
end
end end
if(neg_pos+10>neg_free),neg_free=neg_free+10000;neg_list((neg_pos+1):neg_free,:)=0;
dist =abs(neg_list(1:neg_pos,3)-reg_mean);
[pixdist,index]=min(dist); J(x,y)=2; reg_size=reg_size+1;
reg_mean= (reg_mean*reg_size + neg_list(index,3))/(reg_size+1);
x = neg_list(index,1); y = neg_list(index,2);
end
neg_list(index,:)=neg_list(neg_pos,:); neg_pos=neg_pos-1; J=J>1;
Output- - Experiment-12

Result:

Thus the segmentation of images using region growing is performed.


Exp: No.13 FILTERING VIDEO SIGNALS
Date:

AIM
To convert the video image into frames

SOFTWARE MATLAB

THEORY

Television standards conversion is the process of changing a television transmission or


recording from one television system to another. The most common is from NTSC to PAL or the other
way around. This is done so television programs in one nation may be viewed in a nation with a different
standard. The video is fed through a video standards converter, which makes a copy in a different video
system.

PROGRAM

file=aviinfo('movie1.avi'); frm_cnt=file.NumFrames
h = waitbar(0,'Please wait...');
for i=1:frm_cnt
frm(i)=aviread(filename,i); frm_name=frame2im(frm(i));
frm_name=rgb2gray(frm_name); filename1=strcat(strcat(num2str(i)),str2);
imwrite(frm_name,filename1);
waitbar(i/frm_cnt,h) end
close(h)

RESULT
Thus the video is converted into frames.
Exp: No.14 EROSION AND DILATION OPERATIONS OF AN
IMAGE
Date:

AIM
To perform the audio and video signal processing.

SOFTWARE
MATLAB
THEORY
In signal processing, a filter is a device or process that removes some unwanted components or
features from a signal. Filtering is a class of signal processing, the defining feature of filters being the
complete or partial suppression of some aspect of the signal. Most often, this means removing some
frequencies or frequency bands. However, filters do not exclusively act in the frequency domain;
especially in the field of image processing many other targets for filtering exist. Correlations can be
removed for certain frequency components and not for others without having to act in the frequency
domain. Filters are widely used in electronics and telecommunication, in radio, television,
audio recording, radar, control systems, music synthesis, image processing, and computer graphics.
PROGRAM
myvoice= audiorecorder (8000,24,1); disp ('Start to speak.')
recordblocking (myvoice,3) disp('End of recording') play (myvoice)
voice_vector = getaudiodata(myvoice); figure(1)
Plot (voice_vector)
title('Own Voice in Time Domain');
OUTPUT - Experiment14

RESULT
Thus the video and audio signal processing is performed.
Exp: No.15 COLOR IMAGE SEGMENTATION ALGORITHM

Date:

AIM

To perform the following operations in an image (a) erosion, (b) dilation.

SOFTWARE
MATLAB
THEORY
Morphology is a broad set of image processing operations that process images based on shapes.
Morphological operations apply a structuring element to an input image, creating an output image of the
same size. In a morphological operation, the value of each pixel in the output image is based on a
comparison of the corresponding pixel in the input image with its neighbors. The most basic
morphological operations are dilation and erosion. Dilation adds pixels to the boundaries of objects in an
image, while erosion removes pixels on object boundaries. The number of pixels added or removed from
the objects in an image depends on the size and shape of the structuring element used to process the image.
In the morphological dilation and erosion operations, the state of any given pixel in the output image is
determined by applying a rule to the corresponding pixel and its neighbors in the input image. The rule
used to process the pixels defines the operation as a dilation or an erosion. This table lists the rules for
both dilation and erosion. Dilation and erosion are often used in combination to implement image
processing operations. For example, the definition of a morphological opening of an image is an erosion
followed by a dilation, using the same structuring element for both operations. We can combine dilation
and erosion to remove small objects from an image and smooth the border of large objects
PROGRAM
(a) erosion clc;
po=imgetfile; I =
imread(po);
originalBW = I; se =
strel('disk',11);
erodedBW = imerode(originalBW,se);
imshow(originalBW), figure,
imshow(erodedBW);
(b) dilation clc;
po=imgetfile; I =
imread(po); se =
strel('ball',5,5); I2 =
imdilate(I,se);
imshow(I),
title('Original')
figure, imshow(I2),
title('Dilated')
RESULT
Thus erosion and dilation operations in an image is performed.
Exp No.: 16. COLOR IMAGE SEGMENTATION ALGORITHM DEVELOPMENT

Date

AIM: To perform Color Image Segmentation algorithm development

SOFTWARE
MATLAB
THEORY
Image Segmentation:
Image segmentation is the division of an image into regions or categories, which correspond to
different objects or parts of objects. Every pixel in an image is allocated to one of a number of these
categories. A good segmentation is typically one in which: pixels in the same category have similar
grayscale of multivariate values and form a connected region, neighboring pixels which are in different
categories have dissimilar values.
Segmentation is often the critical step in image analysis: the point at which we move from
considering each pixel as a unit of observation to working with objects (or parts of objects) in the image,
composed of many pixels. If segmentation is done well then all other stages in image analysis are made
simpler.
A great variety of segmentation methods has been proposed in the past decades, and some
categorization is necessary to present the methods properly here. A disjunct categorization does not seem
to be possible though, because even two very different segmentation approaches may share properties
that defy singular categorization. The categorization presented in this chapter is therefore rather a
categorization regarding the emphasis of an approach than a strict division.
The following categories are used:
• Threshold based segmentation. Histogram thresholding and slicing techniques are used to
segment the image. They may be applied directly to an image, but can also be combined with pre-
and post-processing techniques.
• Edge based segmentation. With this technique, detected edges in an image are assumed to
represent object boundaries, and used to identify these objects.
• Region based segmentation. Where an edge based technique may attempt to find the object
boundaries and then locate the object itself by filling them in, a region based technique takes the
opposite approach, by (e.g.) starting in the middle of an object and then “growing” outward until
it meets the object boundaries.
PROGRAM
he = imread('hestain.png'); imshow(he),
title('H&E image');
text(size(he,2),size(he,1)+15,...
'Image courtesy of Alan Partin, Johns Hopkins University', ...
'FontSize',7,'HorizontalAlignment','right');
cform = makecform('srgb2lab');
lab_he = applycform(he,cform);
ab = double(lab_he(:,:,2:3));
nrows = size(ab,1); ncols =
size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 3;
% repeat the clustering 3 times to avoid local minima
[cluster_idx, cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean', ... 'Replicates',3);

pixel_labels = reshape(cluster_idx,nrows,ncols); imshow(pixel_labels,[]),


title('image labeled by cluster index');
segmented_images = cell(1,3); rgb_label =
repmat(pixel_labels,[1 1 3]); for k = 1:nColors color = he;
color(rgb_label ~= k) = 0; segmented_images{k} = color;
end imshow(segmented_images{1}), title('objects in cluster
1'); imshow(segmented_images{2}), title('objects in cluster
2');

OUTPUT:

RESULT:

Thus the Color Image Segmentation algorithm development is performed.


Exp No :17 MORPHOLOGICAL OPERATIONS IN
Date: ANALYZING IMAGE STRUCTURES

AIM :To perform Morphological operations in analyzing image structures.


SOFTWARE
MATLAB
THEORY
The morphological transformations extract or modify the structure of the particles in an image.
Such transformations can be used to prepare the particles for the quantitative analysis, for the analysis of
the geometrical properties or for extracting the simplest modeling shapes and other operations. The
morphological operations can also be used for expanding or reducing the particle dimensions, gap
“filling” or closing inclusions, the averaging of the particle edges and others. The morphological
transformations are separated in two main categories:
• binary morphological functions, which are applied for binary images
• gray-level morphological functions, which are applied for gray-level images
A binary image is an image which was segmented into an object region (which contains particles –
typically the object pixels are coded by ones) and a background region (typically the background pixels
are coded by zeros). The most simple segmentation process is by binary thresholding the gray-level
images.
PROGRAM
BW =
imread(‘circles.png’);
imshow(BW); BW2 =
bwmorph(BW,’remove’); figure
imshow(BW2); BW3
=
bwmorph(BW,’skel’,Inf); figure
imshow(BW3) ;
BW1 =
Array(imread(‘circles.png’)); figure
imshow(BW1) ; BW2
=
bwmorph(BW1,’remove’); figure
imshow(BW2) ; BW3
=
bwmorph(BW1,’skel’,Inf); figure imshow(BW3);
OUTPUT:

RESULT:
Thus the Morphological operations in analyzing image structures is performed
Exp: No: 18
Date: NUMBER PLATE DETECTION

ABSTRACT:
Number plate detection is based on image processing technology. It is used to detect
the vehicle number plate. Vehicle communication plays a major role in today’s
scenario. Traffic management has become one of the most difficult tasks. With the
increasing of vehicles, the crimes are also getting increased. It helps to inspect crimes
on the public roads. This is proposed to detect, extract, recognize and authenticate
vehicle number plates. Different processes like edge detection using sobel operator, a
series of morphological operations, character segmentation using connected
component analysis, character recognition using template matching technique are
used in the proposed method. This technique can also be implemented in the entrance
for security control of a highly restricted area like military zones or area around top
government offices. For example, parliament, supreme court etc. And also, this
system is widely used in traffic control areas, tolling, parking etc. Detection of number
plate in the blurry conditions is the most challenging issue. This system is mainly
designed for the purpose of security system.

1. INTRODUCTION:
In the modern era, the usage of automobiles has been increasing day by day. With
increase of these vehicles there is a need for surveillance of these vehicles for the
protective purpose. The need for the surveillance is mainly used in colleges,
apartments, public areas like shopping malls, parking areas etc., where a gathering of
vehicles takes place. There are many ways to monitor the vehicles through the license
plate of the vehicle. A license plate is also known as a vehicle registration plate which
is attached to the both sides of the vehicle (i.e., front and back). A license plate is an
officially identification provided to the vehicle by the government. The license plate
varies from country to country. The Indian license is provided with a unique code for
every vehicle consisting of state code, district code, where the vehicle is registered
and an alphanumeric unique code e.g. AP 23 PV 1234. The first two letters of the
Indian license plate are denoting the union territory or state, of which there are 29 in
India. The next two digits are indicating the regional transport authority within the
state followed by one or two letters showing the current series of the registration
numbers and the final four numbers are unique to the plate.
The process of working involves a soon as the vehicle enters the secured area the system
automatically captures the images and stores it. The processing of the image is done through
the software stored in the system. If the vehicle matches the already stored information then
it’s allowed to pass the gate. And if the vehicle is not recognized or if it’s marked in the blocked
list then it’s not allowed to cross the gate and further checking process are followed. There are
also algorithms which are based on a combination of morphological operation, segmentation
and canny edge detector. License plate location algorithm consist of steps like as edge
detection, Morphological operation like dilation and erosion, soothing, segmentation of
characters and recognition of plate characters.

2. METHODOLOGY:
Methodology in processing an image:

Figure :1 Block diagram of NPR system


The working of full NPR system as shown in Figure 1 can be divided in to two broad
sections. The hardware part and the software part. The working mechanism of all the
parts is described in details below.
Software Model: The first and the most important part in this process is the software
model. The software model uses the image processing technology. The programs are
implemented in MATLAB.

3. WORK FLOW PROCESS:


The algorithm is divided into following parts: Capture image, Pre-processing, Plate
region extraction, Segmentation of character in the extracted number plate, Character
recognition, Comparison with database and Indicate result. The flow chart of license
plate recognition system implementation in this work is shown in the following Figure
2. There are various steps in this approach and these are implementation in MATLAB.
Figure 2: Working process for number plate detection

Capture of Image: The first step is the capture of image. The image is captured by
electronic device. Digital Camera or Webcam. The image captured is stored in JPEG
format. Later on, it is converted in to gray scale image in MATLAB.

Pre-processing: The next step after capturing the image is the pre-processing of the
image. When the image is captured there is lot of disturbances and noises present in
the image for which the image can’t be used properly. So, in this step the noises from
the image are required to be cleared to obtain an accurate result.
a. Gray Processing: this step involves the conversion of image in to Gray levels.
Color images are converted in to Gray image. According to the R, G, B value in the
image, it calculates the value of gray value, and obtains the gray image at the same
time.
b. Median Filtering: media filtering is the step to remove the noises from the image.
Gray level cannot remove the noises. So, to make image free from noise media filtering
is used.

Plate region extraction: The most important stage is the extraction of number plate
from eroded image significantly. The extraction can be done by using image
segmentation method. There are numerous image segmentation methods available in
various literatures. In most of the methods image binarization is used.

Character segmentation: In this step get the o/p of extracted number plate using
labelling components, and then separate each character and split the each and every
character in the number plate image by using split and also find the length of the
number plate, then find the correlation and database if both the value is same means it
will generate the value 0-9 and A - Z, and finally convert the value to string and display
it in edit box, and also store the character in some text file in this code. The character
recognition is now used to compare the each, individual character with the character
stored in the database. OCR uses the correlation method to match the characters. And
if both the character matches then it displays the authorized otherwise it will display
the unauthorized.

Hardware Model: The hardware model consists microcontroller for controlling the
complete hardware of the ANPR system. The ANPR algorithm on a PC receives the
image and performs the processing, which Yields the vehicle number. This Number is
then compared to standard database and finally provides signal to microcontroller to
control the system Hardware. If the inputted plate contains the authorized number then
the green indication light will be switched on w, and if the inputted plate contains an
unauthorized number then red indication will be switched-on.

4. RESULT:

Figure 3: screenshot ofvthe simulated output

Figure 4:vScreenshot of simulated output

The number plate detection as shown in Figure 3 and 4 using image processing has been
verified using Matlab.
5. Conclusion:
In this project, we have developed a prototype that can detect the number plate using
MATLAB and image processing. It has been tested at various cases and has turned out
to be successful. However, it can sometimes be unsuccessful when the image is not
clear or the number plate is gaudy. We can develop this project into a better one and
more efficient by using various technologies like Artificial Intelligence.

References:

1. Faour, Reham & Shanwar, Bassel & Zarka, Nizar. (2016). Recognition of Vehicle
Number plate using Matlab. 10.13140/RG.2.1.1459.8640.
2. Recognition of number plate by matlab by N. Ratnakar
3. Vehicle Number Plate Detection Using Matlab by Narendra Singh Tomar,Prakhar
Sachan.
4. Matlab Based Vehicle Number Plate Recognition by Ms. Shilpi Chauhan.
5. D. Jiang, T. M. Mekonnen, T. E. Merkebu and A. Gebrehiwot, "Car Plate
Recognition System," 2012 Fifth International Conference on Intelligent
Networks and Intelligent Systems, 2012, pp. 9-12, doi: 10.1109/ICINIS.2012.55.

You might also like