Morpho

30
MORPHOLOGICAL BACKGROUND DETECTION & ENHANCEMENT OF IMAGES WITH POOR LIGHTING An industry Oriented Mini Project submitted to the Jawaharlal Nehru Technology University in partial fulfillment of the requirements for the award of the Degree of BACHELOR OF TECHNOLOGY IN ELECTRONICS AND COMMUNICATION AND ENGINEERING Submitted By K.Sindhu G.V.Charan Tej M.Srinivasulu 07AJ1A0444 07AJ1A0412 07AJ1A0423 DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING AMRITA SAI INSTITUTE OF SCIENCE AND TECHNOLOGY (APPROVED BY AICTE, NEW DELHI; AFFILIATED TO JNTU, KAKINADA) 1

description

 

Transcript of Morpho

Page 1: Morpho

MORPHOLOGICAL BACKGROUND DETECTION &ENHANCEMENT OF IMAGES WITH POOR LIGHTING

An industry Oriented Mini Project submitted to the Jawaharlal Nehru Technology University in partial fulfillment of the requirements for the award of the Degree of

BACHELOR OF TECHNOLOGY

IN

ELECTRONICS AND COMMUNICATION AND ENGINEERING

Submitted By

K.Sindhu G.V.Charan Tej M.Srinivasulu 07AJ1A0444 07AJ1A0412 07AJ1A0423

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

AMRITA SAI INSTITUTE OF SCIENCE AND TECHNOLOGY

(APPROVED BY AICTE, NEW DELHI; AFFILIATED TO JNTU, KAKINADA)

PARITALA, KRISHNA DISTRICT – 521 180 (A. P.)

NOV-DEC 2010

1

Page 2: Morpho

CERTIFICATE

This is to certify that K.Sindhu(07AJ1A0444), G.V.Charan

tej(07AJ1A0412), M.Srinivasulu(07AJ1A0423) Students of B.Tech (Electronics And

Communication Engineering) IV-I Semester have successfully completed their project work,

titled “MORPHOLOGICAL BACKGROUND DETECTION & ENHANCEMENT OF

IMAGES WITH POOR LIGHTING” at AMRITA SAI INSTITUTE OF SCIENCE AND

TECHNOLOGY during the Academic year 2009-2010. This is submitted as a partial fulfillment

for the award of the Degree B.Tech( Electronics And Communication Engineering) and is not

submitted else where.

Head of the Department

(Mr.B.RamaRao)

2

Page 3: Morpho

ACKNOWLEDGEMENTS

We would like to express our deepest gratitude to Dr. P. V. SUBBAIAH Principal,

Amrita Sai Institute of science and Technology.

We are grateful to the Head of the Department of ECE Mr.B.RamaRao, under the

supervision of their assistance and encouragement in carrying out the project.

We sincerely thank all the faculty and staff members of the Department of ECE for their

kind co-operation.

Finally we thank one and all who directly or indirectly helped us to complete our

mini project successfully.

Yours Sincerely,K.Sindhu

G.V.Charan tejM.Srinivasulu

3

Page 4: Morpho

CONTENTS

ABSTRACT 1. INTRODUCTION

1.1 Morphology1.2 Morphological Transformations

2. PROPOSED METHOD

2.1 Background detection by block analysis 2.2 Background detection using morphological operations 2.3 Structuring element 2.4 Histogram equalization

3. CODING

4. RESULT & CONCLUSION

4

Page 5: Morpho

ABSTRACT:

In this project, some morphological transformations are used to detect the background in

images characterized by poor lighting. Lately, contrast image enhancement has been carried out

by the application of two operators based on the Weber’s law notion. The first operator employs

information from block analysis, while the second transformation utilizes the opening by

reconstruction, which is employed to define the multi background notion.

When we are taking the image, the flash will fall on the target and reflects back to the

lens. Then the monochrome image will be formed. The image may be dark or poor lightening.

Due poor lightening the background of the image is not clear. This image can be enhanced by

lightening the back ground. It employs the division of whole image of into several blocks. Each

block consists of pixels. Find out the minimum and the maximum values of the pixels in that

block. Calculate the average value of the pixel. Now change the values of the remaining pixels in

the block to the average value. We do the same process for the remaining blocks also. Then the

enhanced image is formed. Consider the each pixel in the original image in enhanced image and

corresponding pixel in original image and thus combine these pixels using Weber’s law. Thus a

reconstructed image is obtained. In this way the background lightening can be enhanced.

5

Page 6: Morpho

1. INTRODUCTION

The world is filled with images, which are representations of objects and

scenes in the real world. Images are represented by an array of pixels, which can represent the

gray levels or colors of the image. There are many aspects of images that are ambiguous and

uncertain. Examples of these vague aspects include determining the border of a blurred object

and determining which gray values of pixels are bright and which are dark Sometimes an image

may be too dark contains blurriness and therefore difficult to recognize the different objects or

scenery contained in the image. Image enhancement algorithms are applied to remotely sensed

data to improve the appearance of an image for human visual analysis or occasionally for

subsequent machine analysis. The objective of image enhancement is dependent on the

application context; criteria for enhancement are often subjective or too complex to be easily

converted to useful objective measures. Image enhancement techniques are widely used in many

fields, where the subjective quality of images is important. Many algorithms for achieving

contrast enhancement have been developed. Those enhancement algorithms can be classified into

two types point operations, which are global and spatial neighborhood techniques, which are

local.

In this work, two methodologies to compute the image background are

proposed. Also, some operators to enhance and normalize the contrast in grey level images with

poor lighting are introduced. Contrast operators are based on the logarithm function in a similar

way to Weber’s law. The use of the logarithm function avoids abrupt changes in lighting. Also,

two approximations to compute the background in the processed images are proposed using Mat

lab Simulink. The first proposal consists in an analysis by blocks, whereas in the second

proposal, the opening by reconstruction.

Even though morphological contrast has been largely studied, there are no

methodologies, from the point of view MM, capable of simultaneously normalizing and

enhancing the contrast in images with poor lighting. On the other side, one of the most common

techniques in image processing to enhance dark regions is the use of nonlinear functions, such as

logarithm or power functions ; otherwise, a method that works in the frequency domain is the

homomorphic filter . In addition, there are techniques based on data statistical analysis, such as

6

Page 7: Morpho

global and local histogram equalization. During the histogram equalization process, grey level

intensities are reordered within the image to obtain a uniform distributed histogram. However,

the main disadvantage of histogram equalization is that the global properties of the image cannot

be properly applied in a local context, frequently producing a poor performance in detail

preservation. In, a method to enhance contrast is proposed; the methodology consists in solving

an optimization problem that maximizes the average local contrast of an image.

1.1 Morphology:

Morphology is a technique of image processing based on shapes. 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. By choosing the size and shape of the neighborhood, you can construct a

morphological operation that is sensitive to specific shapes in the input image.

Mathematical morphology is a set-theoretical approach to multi-dimensional digital

signal or image analysis, based on shape. It is a theory and technique for the analysis and

processing of geometrical structures, based on set theory, lattice theory, topology, and random

functions. It is most commonly applied to digital images, but it can be employed as well on

graphs, surface meshes, solids, and many other spatial structures.

It is also the foundation of morphological image processing, which consists of a set of

operators that transform images according to the above characterizations.

Mathematical morphology was originally developed for binary images, and was later

extended to scale functions and images. The subsequent generalization to complete lattices is

widely accepted today as MM's theoretical foundation.

1.2 Morphological transformations:

Basically morphological transformations such as erosion, dilation, opening & closing

are used to detect the background.

Erosion:

Erosion is one of the two basic operators in the area of mathematical morphology, the

other being dilation. It is typically applied to binary images, but there are versions that work on

gray scale images. The erosion operator takes two pieces of data as inputs. The first is the image

7

Page 8: Morpho

which is to be eroded. The second is a (usually small) set of coordinate points known as a

structuring element (also known as a kernel). It is this structuring element that determines the

precise effect of the erosion on the input image. In erosion, every object pixel that is touching a

background pixel is changed into a background pixel.

Gray scale erosion with a flat disk shaped structuring element will generally

darken the image. Bright regions surrounded by dark regions shrink in size, and dark regions

surrounded by bright regions grow in size. Small bright spots in images will disappear as they

are eroded away down to the surrounding intensity value, and small dark spots will become

larger spots. The effect is most marked at places in the image where the intensity changes

rapidly, and regions of fairly uniform intensity will be left more or less unchanged except at their

edges.

Dilation:

Dilation adds pixels to the boundaries of objects in an image. In

dilation, every background pixel that is touching an object pixel is changed into an object pixel .

Note how the function applies the rule to the input pixel's neighborhood and uses the highest

value of all the pixels in the neighborhood as the value of the corresponding pixel in the output

image.

8

Page 9: Morpho

2. PROPOSED METHOD

In this project there are two approximations to compute the backgrounds in the processed

images are proposed using Matlab simulink. The first proposal consists in an analysis by blocks,

whereas in the second proposal, morphological operators are used.

2.1 Background Detection by Block Analysis:

In this analysis, first of all we will read an image as input image and divide it into several

blocks and from each block we will determine the background and apply the weber’s law and

thereby we obtain an enhanced image

Fig. 2.1.1 Block diagram of Background Detection by Block Analysis

Let us consider an image which is to be enhanced. The image is divided into n

blocks of size. Each block is a sub image of the original image. As the image is made up of

number of pixels each block consists of number of pixels. Find the maximum and minimum

intensity values of pixels of each block.

For each analyzed block, maximum (Mi) and minimum (mi) values are used to

determine the background criteria Ti in the following way:

9

Page 10: Morpho

In the 1-D case, as illustrated in Fig, the following expression is obtained:

Fig. 2.1.2: Background criteria obtained by block analysis.

Once Ti is calculated, this value is used to select the background parameter

associated with the analyzed block. As follows, an expression to enhance the contrast is

proposed:

Note that the background parameter depends on the Ti

value. If f<= Ti(dark region), the background parameter takes the value of the

maximum intensity(Mi) within the analyzed block, and the minimum

intensity(mi) value otherwise. Also, the unit was added to the logarithm

function in above equation to avoid indetermination. On the other hand,

since grey level images are used in this work, the constant Ki in above

equation is obtained as follows:

10

Page 11: Morpho

On the other hand, M i. and mi values are used as background parameters to

improve the contrast depending on the Ti value, due to the background is different for clear and

dark regions. Now an image is formed by applying the above equation. Now consider a pixel in

this image and the corresponding pixel in original image. Combine them using Weber’s law

which can be stated as follows. Thus an enhanced image is formed.

Weber’s Law:

In psycho-visual studies, the contrast C of an object with luminance Lmax against its

surrounding luminance Lmin is defined as follows

If L=Lmin and =Lmax-Lmin so it can be written as follows

In the above Equation indicates that(log L) is proportional to C. Therefore, Weber’s law can be

expressed as

Where k and b are constants, b being the background. In this case, an approximation

to Weber’s law is considered by taking the luminance L as the grey level intensity of a function

(image); in this way, above expression is written as follows

2.2 Background detection using morphological operators:

On the other hand, given that, maximum and minimum

values are analyzed for each block, an extension using morphological

operators is presented as follows.

11

Page 12: Morpho

Fig. 2.2 Block diagram of Background Detection by Erosion & Dilation

Morphological operations:

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. By choosing

the size and shape of the neighborhood, you can construct a morphological operation that is

sensitive to specific shapes in the input image. Dilation and erosion are two fundamental

morphological operations. 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.

Rules for Dilation and Erosion:

12

Page 13: Morpho

Operation Rule

Dilation

Erosion

The value of the output pixel is the maximum value of all the pixels in the input

pixel's neighborhood. In a binary image, if any of the pixels is set to the value 1,

the output pixel is set to 1.

The value of the output pixel is the minimum value of all the pixels in the input pixel's neighborhood. In a binary image, if any of the pixels is set to 0, the output pixel is set to 0.

Erosion:

Erosion is one of the two basic operators in the area of mathematical morphology,

the other being dilation. It is typically applied to binary images, but there are versions that work

on gray scale images. The erosion operator takes two pieces of data as inputs. The first is the

image which is to be eroded. The second is a (usually small) set of coordinate points known as a

structuring element (also known as a kernel). It is this structuring element that determines the

precise effect of the erosion on the input image. In erosion, every object pixel that is touching a

background pixel is changed into a background pixel.

Dilation:

Dilation adds pixels to the boundaries of objects in an image. In dilation, every

background pixel that is touching an object pixel is changed into an object pixel. Note how the

function applies the rule to the input pixel's neighborhood and uses the highest value of all the

pixels in the neighborhood as the value of the corresponding pixel in the output image.

Let Imax(x) and Imin(x) be the maximum and minimum intensity

values taken from one set of pixels contained in a window (B) of elemental

13

Page 14: Morpho

size (3 X 3 elements), x belongs to D. Notice that the window corresponds to

the structuring element .A new expression can be derived as shown:

Where Imax(x) and Imin(x) values correspond to the

morphological dilation and erosion defined by the order-statistical filters.

Thus, the above expression is expressed as

Finally the proposed transformation is expressed as

2.3 Structuring Elements:

An essential part of the dilation and erosion operations is the structuring

element used to probe the input image. A structuring element is a matrix consisting of only 0's

and 1's that can have any arbitrary shape and size. The pixels with values of 1 define the

neighborhood.

Two-dimensional, or flat, structuring elements are typically much smaller than

the image being processed. The center pixel of the structuring element, called the origin,

14

Page 15: Morpho

identifies the pixel of interest -- the pixel being processed. The pixels in the structuring element

containing 1's define the neighborhood of the structuring element. These pixels are also

considered in dilation or erosion processing.

Three-dimensional, or nonflat, structuring elements use 0's and 1's to define

the extent of the structuring element in the x- and y-planes and add height values to define the

third dimension.

Origin of a Structuring Element:

The morphological functions use this code to get the coordinates of the

origin of structuring elements of any size and dimension

Origin = floor ((size (nhood) +1)/2) (1)

Here nhood is the neighborhood defining the structuring element. Because structuring

elements are MATLAB objects, we cannot use the size of the STREL object itself in this

calculation. We must use the STRELgetnhood method to retrieve the neighborhood of the

structuring element from the STREL object.

For example, the following illustrates a diamond-shaped structuring element

Fig. 4.3 a diamond-shaped structuring elemen

Creating a Structuring Element:

The toolbox dilation and erosion functions accept structuring element

objects, called STRELs. We use the strel function to create STRELs of any arbitrary size and

shape. The strel function also includes built-in support for many common shapes, such as lines,

diamonds, disks, periodic lines, and balls.

For example, this code creates a flat, diamond-shaped structuring element.

se = strel ('diamond', 3)

15

Page 16: Morpho

. where 3 specifies the distance from the structuring element origin to the points

of the diamond.

2.4 Histogram Equalization:

Histogram equalization is a method in imageprocessing of contrast

adjustment using the image'shistogram. This method usually increases the global contrast of

many images, especially when the usable data of the image is represented by close contrast

values. Through this adjustment, the intensities can be better distributed on the histogram. This

allows for areas of lower local contrast to gain a higher contrast without affecting the global

contrast. Histogram equalization accomplishes this by effectively spreading out the most

frequent intensity values.

The method is useful in images with backgrounds and foregrounds that

are both bright or both dark. In particular, the method can lead to better views of bone structure

in x - ray images, and to better detail in photographs that are over or under-exposed.

Histogram equalization often produces unrealistic effects in photographs;

however it is very useful for scientific images like thermal, satellite or x-ray images, often the

same class of images that user would apply false-color to. Also histogram equalization can

produce undesirable effects (like visible image gradient) when applied to images with low color

depth.

Figure shows that for any given mapping function y=f(x) between the

input and output Images, the following holds p(y) dy=p(x) dxi.ie., the number of pixels mapped

from x to y is unchanged.

16

Page 17: Morpho

3.CODING

Main:

clc

clear all

close all

[file path]=uigetfile('*.jpg');

I=imread([path file]);

eqn10(I); % IMAGE BACKGROUND APPROXIMATION BY BLOCKS

eqn13(I);

% histogram_eq(I); % HISTOGRAM EQUALIZATION

Eqn10:

function eqn10(I)

figure,imshow(I);title('Original Image');

I=imresize(I,[256 256]);

I=rgb2gray(I);

I=double(I);

17

Page 18: Morpho

xw=8;

for i=1:size(I,1)/xw

for j=1:size(I,2)/xw

B=I(((i-1)*xw)+1:i*xw,(((j-1)*xw))+1:j*xw);

m=min(min(B))/255;

M=max(max(B))/255;

t=(m+M)/2;

BB=blockkk(m,M,t,B,xw);

I1(((i-1)*xw)+1:i*xw,(((j-1)*xw))+1:j*xw)=BB;

end

end

figure,subplot(1,2,1)

imshow(I,[]);title('Original Image');

subplot(1,2,2)

imshow(I1,[]);title('Enhanced Image: Eqn 10');

% Histogram

figure,

subplot(1,2,1),imhist(uint8(I))

title('INPUT IMAGE')

axis([0 255 0 8000])

subplot(1,2,2),imhist(uint8(I1))

title('IMAGE EQN10')

axis([0 255 0 8000])

% Disply Graph

figure,plot(I(25,:),'r'),hold on

18

Page 19: Morpho

plot(I1(size(I,1)/2,:),'g')

% axis([0 255 0 260])

legend('Input Image','Out put Image')

xlabel('Intensity level')

ylabel('Image Values')

title('IMAGE BACKGROUND APPROXIMATION BY BLOCKS EQN10')

function BB=blockkk(m,M,t,B,xw)

BB=zeros(xw);

for i=1:xw

for j=1:xw

f=B(i,j);

if f > t

mm=m;

else

mm=M;

end

k=(255-mm)/log(256);

if f<=t

BB(i,j)=k*log(f+1)+M;

else

BB(i,j)=k*log(f+1)+m;

end

end

end

Eqn13:

function eqn13(I)

I=imresize(I,[256 256]);

I=rgb2gray(I);

19

Page 20: Morpho

I=double(I);

u=1;

radious=2*u+1;

se=strel('square',radious);

xw=8;

for i=1:size(I,1)/xw

for j=1:size(I,2)/xw

B=I(((i-1)*xw)+1:i*xw,(((j-1)*xw))+1:j*xw);

BB=formula(B,se);

I1(((i-1)*xw)+1:i*xw,(((j-1)*xw))+1:j*xw)=BB;

end

end

figure,subplot(1,2,1)

imshow(I,[]),title('Original Image')

subplot(1,2,2)

imshow(I1,[]);title('eqn13 Image')

% Histogram

figure,

subplot(1,2,1),imhist(uint8(I))

title('INPUT IMAGE')

axis([0 255 0 8000])

subplot(1,2,2),imhist(uint8(I1))

title('IMAGE EQN13')

axis([0 255 0 8000])

% Disply Graph

figure,plot(I(size(I,1)/2,:),'r'),hold on

plot(I1(size(I,1)/2,:),'g'),axis([0 255 0 260])

legend('Input Image','Out put Image')

xlabel('Intensity level')

20

Page 21: Morpho

ylabel('Image Values')

title('IMAGE BACKGROUND APPROXIMATION BY BLOCKS EQN13')

function I1=formula(I,se)

I1=zeros(size(I,1));

E=imerode(I,se);

D=imdilate(I,se);

for i=1:size(I,1)

for j=1:size(I,2)

e=E(i,j);

d=D(i,j);

f=I(i,j);

t=(e+d)/2;

k=(255-t)/log(256);

if f<=t

I1(i,j)=k*log2(f+1)+d;

else

I1(i,j)=k*log2(f+1)+e;

end

end

end

Histogram eqn:

function histogram_eq(I)

I=imresize(I,[256 256]);

I=rgb2gray(I);

I1=histeq(I);

figure,subplot(1,2,1)

imshow(I,[]),title('Original Image')

subplot(1,2,2)

imshow(I1,[]),title('Histogram Equalization')

21

Page 22: Morpho

% Histogram

figure, subplot(1,2,1),imhist(uint8(I))

title('INPUT IMAGE')

axis([0 255 0 8000])

subplot(1,2,2),imhist(uint8(I1))

title('HIST EQUAIZATION')

axis([0 255 0 8000])

% Disply Graph

figure,plot(I(size(I,1)/2,:),'r'),hold on

plot(I1(size(I,1)/2,:),'g'),axis([0 255 0 260])

legend('Input Image','Out put Image')

xlabel('Intensity level')

ylabel('Image Values')

title('HISTOGRAM EQUALIZATION')

4. RESULT & CONCLUSION

This project presents a study to detect the image background

and to enhance the contrast in binary images with poor lighting. First, a

methodology was introduced to compute an approximation to the

background using blocks analysis. This proposal was subsequently

extended using mathematical morphology operators.

Let us consider the input image as shown in fig (a) and the

obtained enhanced image which is shown in the fig (b)

22

Page 23: Morpho

Fig (a) Original image

Fig (b) Enhanced image

23