A Project Report On

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 44

A PROJECT REPORT

ON
SHADOW DETECTION AND REMOVAL
Submitted under the supervision of
Dr. Narendra Kohli
(Professor , Computer Science and Engineering Department)
H.B.T.I , KANPUR.

By:
Vartika Pandey (1004510050)
Priyal Khetan(1004555014)
Ankita Gautam(1004510011)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


HBTI KANPUR

INDEX

DECLARATION
CERTIFICATE
ACKNOWLEDGEMENT

Chapter 1.INTRODUCTION
1.1 Title
1.2 Introduction Review
1.3 Background Analysis
Chapter 2.PROJECT OVERVIEW
2.1 What is a Shadow ?
2.2 Geometrical Properties of the Shadow
2.3 Spectral Properties of the Shadow
Chapter 3.OBJECTIVE OF THE PROJECT
Chapter 4.PURPOSE OF THE PROJECT
Chapter 5CURRENT SCOPE OF THE PROJECT
Chapter 6 .CHARACTRESTICS OF PROPOSED SYSTEM
Chapter 7.PROJECT RESEARCH
7.1 Implementation of Image Processing
7.2 Other Morphological Operations
7.3 Advantages of Morphological Operations
Chapter 8. REQUIREMENT ANALYSIS
8.1 Software Requirements
8.2 Functional Requirements
8.3 Hardware Requirements
8.4 Non-Functional Requirements
Chapter 9.PROJECT OPERATIONS

Chapter 10.CODE OF THE PROJECT


Chapter 11 BLOCK DIAGRAM
Chapter12.FEATURES OF THE PROJECT
Chapter 13 :PROJECT MODULES
13.1 Shadow Detection
13.1.1 Segmentation using MASK creation
13.2 Shadow Removal
Chapter 14 :CONTROL FLOW DIAGRAM
Chapter 15:METHOD
15.1 Original Image
15.2 Mask
15.3 Shadow Core
15.4 Light Core
15.5 Smooth Mask
15.6 Output Image
Chapter 16.SHADOW REMOVAL METHODS
16.1 Additive Model
16.2 YCbCr Model
16.3 Basic and Advanced shadow removal method
Chapter 17 Conclusion
Chapter 18 Referrence

\
\

DECLARATION:
This is to declare that the report entitled Shadow Detection and Removal which is
submitted by Vartika Pandey, Priyal Khetanand Ankita Gautam in partial fulfilment of
requirement for the award of Degree of B.Tech, from Computer Science and Engineering
Department ,H.B.T.I ,Kanpur.

Vartika Pandey (1004510050)


Priyal Khetan(1004555014)
Ankita Gautam(1004510011)

CERTIFICATE

This is to certify that this report embodies the original work done by Vartika Pandey ,
Priyal Khetan and Ankita Gautam during this project submission as partial fulfilment
of requirement for the system design project of Bachelor of Technology, Computer
Science and Engineering.

Dr.Narendra Kohli
Department of Computer Science and
Engineering
Harcourt Butler Technological
Institute,Kanpur

ACKNOWLEDGEMENT

Any task in the world cannot be accomplished on a sole basis. It directly or indirectly needs
the overt or covert support of their acquaintances, beloved ones or their faculty heads.
The satisfaction that accompanies the successful completion of any task would be incomplete
without the mention of people whose ceaseless cooperation made it possible and whose
constant guidance and encouragement crowns all efforts with success. We have culminated
our project with the aid of not only our friends also the assistance provided by our faculties
cannot be neglected.
We would like to honour our project guide Dr.Narendra Kohli, for the incredible support he
gave us. He fostered and encouraged us to pursue it to finish it to the rising stars. His
motivation acted as a strength for us. He not only supported us but also showered his
experience drops on our project which makes it embellishing and a full fledged technology.
We are grateful to him for the guidance, inspiration and constructive suggestions that helped
us in the preparation of this project.

CHAPTER 1: INTRODUCTION
1.1TITLE OF THE PROJECT
Shadow Detection and Removal

1.2 INTRODUCTION REVIEW

During bright day light or under strong lighting conditions, shadows will appear and
be part of an object in image. Object's shadow in images may cause problem to
several important algorithm in the fields of image processing such as object
recognition, segmentation and object tracking. Removing the shadows can greatly
improve the result of the image processing .

Shadow detection and removal is an important task when dealing with coloured
outdoor images. Shadows are generated by a local and relative absence of light.
Shadows are, first of all, a local decrease in the amount of light that reaches a surface.

Secondly, they are a local change in the amount of light rejected by a surface toward
the observer. Most shadow detection and segmentation methods are based on image
analysis.

However, some factors will affect the detection result due to the complexity of the
circumstances, like water and a low intensity roof because of the special material as
they are easy mistaken as shadows. In this paper we present a hypothesis test to detect
shadows from the images and then energy function concept is used to remove the
shadow from the image.

The interest of shadow removal is not limited to the detection of the shadow. It is also
sometimes important to nd ways to remove the eect of the shadow while still
keeping the underlying texture of the surfaces.

A shadow is an area where direct light from a light source cannot reach due to
obstruction by an object. There have been few studies concerning shadow removal,
and the existing approaches cannot perfectly restore the original background patterns
after removing the shadows .

The patterns of shadow rely on size of objects and the angles of lighting source. This
may lead to problems in scene understanding, object segmentation, tracking and
recognition. Because of the undesirable effects of shadows on image analysis, much
attention is paid to the area of shadow removal over the past decades and covered

many specific applications such as traffic surveillance, face recognition, image


segmentation and so on .

There are disadvantages like loss of information for the surface under the shadows
present difficulties for image interpretation, image matching, detection and other
applications. There are a number of cues which suggest the presence of shadows in a
visual scene and that are exploited for their detection in digital images and image
sequences .

Shadow removal from respective image can be used for object detection, such as
cancer detection, military object detection etc., as sometimes images are covered by
shadows. After removing these shadows, objects in the images will appear more
obviously so that they are recognized correctly. Shadow detection and removal is an
important task when dealing with colour outdoor images.

1.3BACKGROUND

Shadows are generated by a local and relative absence of light. Shadows are, first of
all, a local decrease in the amount of light that reaches a surface. Secondly, they are a
local change in the amount of light rejected by a surface toward the observer. Most
shadow detection and segmentation methods are based on image analysis.

However, some factors will affect the detection result due to the complexity of the
circumstances, like water and a low intensity roof because of the special material as
they are easy mistaken as shadows. In this paper we present a hypothesis test to detect
shadows from the images and then energy function concept is used to remove the
shadow from the image.

During bright day light or under strong lighting condition, shadows will appear and be
part of an object in image. Object' shadow in images may cause problem to several
important algorithm in the fields of image processing such as object recognition,
segmentation and object tracking. Removing the shadows can greatly improve the
result of the image processing.

To tackle this problem then, this project is divided into three parts; eliminating the
surrounding objects of object interest, detecting shadows region and removing the
object's shadow.

This project used moving object images to distinguish between object focusing and
objects will be eliminated in image. Support Vector Machine (SVM) was used to
classify the image into shadow and non-shadow region based on texture features.

Then, the image of detected shadow region was differentiated with original image to
remove the shadow. In this project, Matlab and Image Processing Toolbox were
utilized and OSU-SVM was used as interface SVM to the Matlab environment.

Due to obstruction by an object light from a source cannot reach the area and creates
shadow on that area. Shadows often introduce errors in the performance of computer
vision algorithms, such as object detection and tracking.

Thus shadow detection and removal is a pre-processing task in these fields. This paper
proposes a simple method to detect and remove shadows from a single RGB image. A
shadow detection method is selected on the basis of the mean value of RGB image in
A and B planes of LAB equivalent of the image and shadow removal method is based
on the identification of the amount of light impinging on a surface.

CHAPTER 2 PROJECT OVERVIEW

2.1What is a Shadow?
A shadow occurs when an object partially or totally occludes direct light from a source of
illumination. It can be classified into two groups: self shadow and cast shadow. Self shadow
is the region of shadow which is projected on the object where as cast shadow is the region of
shadow which is projected on the surface or background . Again cast shadow can be
classified into two parts: umbra and penumbra. The part of cast shadow where direct light can
not reach completely due to obstruction by object is called 9umbra. The part of cast shadow
where direct light is not completely blocked by object is called penumbra.

2.2Geometric property of shadow


The geometric functions and relations are very useful for shadow extraction. There is single
light source. Light is obstructed by the object and shadow is formed. ABCD is self shadow
region.EDC is cast shadow region. The intensity of self shadow pixels is lower than intensity
of cast shadow pixels. The intensity of directly illuminated part of object is grater than both
of cast shadow and self shadow pixels.
2.3 Spectral properties of shadow
This represents the intensity of the reflected light at a point in a shadow region. Geometric
property of shadow is very useful for shadow extraction. There is single light source. Light is
obstructed by the object and shadow is formed. ABCD is self shadow region.EDC is cast
shadow region. The intensity of self shadow pixels is lower than intensity of cast shadow
pixels. The intensity of directly illuminated part of object is greater than both of cast shadow
and self shadow pixels. This represents the intensity of the reflected light at a point in a
shadow region.

CHAPTER 3
OBJECTIVE OF THE PROJECT : This paper describes a method for automatic detection and removal of
shadow segments in RGB images with least possible manual
intervention .

The entire algorithm involves dealing with the shadow parts of the RGB
image.

The non-shadow parts of the image which henceforth acts as the input
should be least affected by this method leading to no undesirable loss of
information .

CHAPTER 4
PURPOSE OF THE PROJECT

Shadows and shadings in images lead to undesirable problems on image analysis.


Thats why much attention was paid to the area of shadow detection and removal over
the past decades and covered many specific applications such as traffic surveillance,
face recognition and image segmentation .

Removing shadows from images can significantly improve and facilitate the
performance of certain computer vision tasks, such as tracking, segmentation, and
object detection etc. It is therefore of great importance to discover ways of properly
detecting shadows and removing them while keeping other details of the original
image intact.

Hence we aim at Shadow detection and removal from the image with least manual
intervention .

CHAPTER 5
CURRENT SCOPE OF THE PROJECT

Shadow is one of the major problems in remotely sensed imagery which hampers the
accuracy of information extraction and change detection. In these images, shadow is
generally produced by different objects, namely, cloud, mountain and urban materials.

Several issues including the problems and the advantages of those algorithms are
discussed. One of the most common types of error encountered in remotely sensed
data is shadow. This problem is a major source of confusion and misclassification in
extracting land cover information from remote sensing data .

Also in the most popular picture editing applications like PICASA , Adobe
photoshop , PHOTO360 , INSTAGRAM ,there are similar provisions for detecting
and removing shadows , but none of these applications eliminate human intervention .

These applications require constant human guidance for edge detection and boundary
blurring , hence our applications wishes to overcome this shortcoming and become
entirely automatic .

CHAPTER 6
CHARACTRESTICS OF THE PROJECT :-

The project aims at removing the dark shadow regions from an image so that those
areas dont create problems during image compression or transmission

It reduces human intervention to the least making the code totally automatic.

It makes the entire process of shadow detection and removal possible without the loss
of any pertinent data

MASK is the binary identifier which helps us detect the shadows .

The project code works best for PNG images

CHAPTER 7
PROJECT RESEARCH

7.1IMPLEMENTATION OF IMAGE PROCESSING

Digital image processing is the use of computer algorithms to perform image


processing on digital images .It allows a much wider range of algorithms to be applied
to the input data and can avoid problems such as the build-up of noise and signal
distortion during processing. Since images are defined over two dimensions (perhaps
more) digital image processing may be modeled in the form of multidimensional
systems.
An image may be defined as a two-dimensional function, f(x, y), where x and y are
spatial (plane) coordinates, and the amplitude of f at any pair of coordinates (x, y) is
called the intensity or gray level of the image at that point.When x, y, and the
amplitude values of f are all finite, discrete quantities, we call the image a digital
image.The field of digital image processing refers to processing digital images by
means of a digital computer.
A digital image is composed of a finite number of elements, each of which has a
particular location and value.These elements are referred to as picture elements,
image elements, pels, and pixels. Pixel is the term most widely used to denote the
elements of a digital image.
Vision is the most advanced of our senses, so it is not surprising that images play the
single most important role in human perception. However, unlike humans, who are
limited to the visual band of the electromagnetic (EM) spectrum, imaging machines
cover almost the entire EM spectrum, ranging from gamma to radio waves.
They can operate on images generated by sources that humans are not accustomed to
associating with images. These include ultrasound, electron microscopy, and
computer-generated images.Thus, digital image processing encompasses a wide and
varied field of applications.
There is no general agreement among authors regarding where image processing stops
and other related areas, such as image analysis and computer vision, start. Sometimes
a distinction is made by defining image processing as discipline in which both the
input and output of a process are images.
For example, under this definition, even the trivial task of computing the average
intensity of an image (which yields a single number) would not be considered an
image processing operation.

On the other hand, there are fields such as computer vision whose ultimate goal is to
use computers to emulate human vision, including learning and being able to make
inferences and take actions based on visual inputs.This area itself is a branch of
artificial intelligence (AI) whose objective is to emulate human intelligence.
The area of image analysis (also called image understanding) is in between image
processing and computer vision. There are no clear-cut boundaries in the continuum
from image processing at one end to computer vision at the other.
However, one useful paradigm is to consider three types of computerized processes in
this continuum:
low-level processing
mid-level processing
high-level processing
Low-level processes involve primitive operations such as image preprocessing to
reduce noise, contrast enhancement, and image sharpening.A low-level process is
characterized by the fact that both
its inputs and outputs are images.
Mid-level processing on images involves tasks such as segmentation (partitioning an
image into regions or objects), description of those objects to reduce them to a form
suitable for computer processing, and classification (recognition) of individual objects
(e.g., edges, contours, and the identity of individual objects).
Finally, higher-level processing involves making sense of an ensemble of
recognized objects, as in image analysis, and, at the far end of the continuum,
performing the cognitive functions normally associated with vision.

7.2 OTHER MORPHOLOGICAL OPERATIONS USED

There are four basic operations for morphological operation on a digital image. Those
are :-

1.
2.
3.
4.

Erosion
Dilation
Opening
Closing.

According to our different requirement, we use different type of these operations. For
each operation we are having structuring element or mask. That mask is superimposed
on the image.

In case of erosion, masking is started from the central pixel of the image and moving
outward. If mask is not completely superimposed on a processing pixel and its
neighbors of the image, all image pixels under mask are discarded. Formally we can
say that erosion shrinks or thins a component in a digital image.

Similarly dilation is operation which expands or thickens a component in a digital


image. In case of dilation if mask is not completely superimposed on a processing
pixel and its neighbors of the image, all image pixels which not under mask are
selected.

Opening generally smoothes the contour of an object and eliminate thin


protrusions which is combination of erosion followed by dilation.

Closing also tends to smooth sections of contours but fusing narrow breaks and long,
thin gulfs and eliminating small holes and filling gaps in the contour which is
combination of dilation followed by erosion.

7.3 ADVANTAGES OF MORPHOLOGICAL OPERATIONS :

The background noise was eliminated during erosion since all noise
components were smaller than the structuring element. Dark spots
noise elements contained within the fingerprint increased in size. This
enlargement was countered by performing dilation that reduced or
completely deleted this noise.
These operations are equivalent to opening, whose effect was to
eliminate almost all noise in image. However, new gaps between the
fingerprint ridges were created. To counter this effect, a dilation on
the opening was performed.

Most of the breaks were restored but the ridges were thickened, which
can be remedied by erosion. The result is equivalent to closing of the
opening

CHAPTER 8
8.1REQUIREMENT ANALYSIS :In our project with a multi layered approach , requiring multiple resources on
detection and removal levels . We have different kinds of requirements which
we have bifurcated into some broad categories that follow :8.1.1Software Requirements :
1.MATLAB

MATLAB (matrix laboratory) is a multi-paradigm numerical computing environment


and fourth-generation programming language. Developed by MathWorks, MATLAB
allows matrix manipulations, plotting of functions and data, implementation ofalgorithms,
creation of user interfaces, and interfacing with programs written in other languages,
including C, C++, Java, and Fortran.Although MATLAB is intended primarily for numerical
computing, an optional toolbox uses the MuPAD symbolic engine, allowing access
to symbolic computing capabilities. An additional package, Simulink, adds graphical multidomain simulation and Model-Based Design for dynamic and embedded systems.
In 2004, MATLAB had around one million users across industry and academia.[3] MATLAB
users come from various backgrounds of engineering, science, and economics. MATLAB is
widely used in academic and research institutions as well as industrial enterprises. Cleve
Moler, the chairman of the computer science department at the University of New Mexico,
started developing MATLAB in the late 1970s.[4] He designed it to give his students access
to LINPACK and EISPACK without them having to learn Fortran. It soon spread to other
universities and found a strong audience within the applied mathematics community. Jack
Little, an engineer, was exposed to it during a visit Moler made to Stanford University in
1983. Recognizing its commercial potential, he joined with Moler and Steve Bangert. They
rewrote MATLAB in C and founded MathWorks in 1984 to continue its development. These

rewritten libraries were known as JACKPAC.[5] In 2000, MATLAB was rewritten to use a
newer set of libraries for matrix manipulation, LAPACK.[6]
MATLAB was first adopted by researchers and practitioners in control engineering, Little's
specialty, but quickly spread to many other domains. It is now also used in education, in
particular the teaching of linear algebra and numerical analysis, and is popular amongst
scientists involved in image processing.

2.Google Chrome .
8.1.2Functional Requirements :
This section describes the functional requirements of the system for those requirements which
are expressed in the natural language style. Shadow detection and removal . Shadows have
always plagued computer vision applications where tracking, segmentation,detection and
recognition algorithms confuse the boundaries of shadows with those of different surfaces or
objects. It is therefore of great interest to discover ways of properly detecting shadows and
removing them while leaving other details of the original image untouched.

8.1.3.3Hardware Requirements:

OS Platform-Windows 7 and onwards.

Main Memory-2 GB

Hard Disk-40 GB

Processor-Intel Core

8.2 NON FUNCTIONAL REQUIREMENTS :

1) Usability
This section includes all of those requirements that effect usability.We get results with
minimum user interaction and tries to remove the shadow entirely from the image. The
software must have a simple, user-friendly interface to save time and confusion.
2) Supportability
The system is designed to be the cross platform supportable. The system is supported on a
wide range of hardware and any software platform with the sole requirement of MATLAB
installation .
3) Implementation
The system is implemented in web environment. It is implemented while having an image
with shadow as the required input to give a shadow-free image as the required output.
Performance Requirements:
The completely separate business logic at server side from the student interface ensures good
performance. The system exhibits high performance because it is well optimized. The
business logic is clearly separate from the UI. We get the response within seconds.

CHAPTER 9
PROJECT OPERATIONS

BLURRING AND SHARPENING OF IMAGES :In shadow removal and detection , we have to perform various types of blurring and
sharpening operations so as to filter the input image and remove the unwanted and
undesirable pictorial elements in a better manner .
These set of operations are not module dependent and can be applied as pre or post
processing analysis.The major significanct points of blurring and sharpening are : Edges and other sharp transtitions in the gray level of an image contribute
significantly to the high-frequency contents of its Fourier Transform
Hence smoothing (blurring ) is achieved in the frequency domain by attenuating a
specified range of high-frequency components in the transform of a given image .
We can employ various filters for this task like Ideal ,Butterworth ,Gaussian filters .
These three filters cover the range from very sharp to very smooth filter order .The
Butterworth has a parameter called Filter Order ,and for very high values of this
parameter , Butterworth exhibits ideal Behavior.
Image sharpening on the other hand can be achieved by a high-pass filtering process
which attenuates the low frequency components without disturbing the high frequency
information in the digital image .
Image sharpening is a powerful tool for emphasizing structure and drawing viewer
focus and is seldom used to concentrate on the shadow areas in a better manner .

CHAPTER 10
CODE OF THE PROJECT :function result = shadowremoval(image, type, mask)
% computing size of the image
s_im = size('c1.PNG');
% creating a shadow segmentation if no mask is available
if (~exist('mask','var'))
gray = rgb2gray('c1.PNG');
mask = 1-double(im2bw(gray, graythresh(gray)));
end
% structuring element for the shadow mask buring, and the shadow/light
% core detection
strel = [0 1 1 1 0; 1 1 1 1 1; 1 1 1 1 1; 1 1 1 1 1; 0 1 1 1 0];
% computing shadow/light core (pixels not on the blured adge of the
% shadow area)
shadow_core = imerode(mask, strel);
lit_core = imerode(1-mask, strel);
% smoothing the mask
smoothmask = conv2(mask, strel/21, 'same');
% averaging pixel intensities in the shadow/lit areas
shadowavg_red = sum(sum(image(:,:,1).*shadow_core)) /
sum(sum(shadow_core));
shadowavg_green = sum(sum(image(:,:,2).*shadow_core)) /
sum(sum(shadow_core));
shadowavg_blue = sum(sum(image(:,:,3).*shadow_core)) /
sum(sum(shadow_core));
litavg_red = sum(sum(image(:,:,1).*lit_core)) / sum(sum(lit_core));
litavg_green = sum(sum(image(:,:,2).*lit_core)) / sum(sum(lit_core));
litavg_blue = sum(sum(image(:,:,3).*lit_core)) / sum(sum(lit_core));
result = image;

% implementation of the different shadow removals


if strcmp(type, 'additive')
% additive shadow removal
% compiting colour difference between the shadow/lit areas
diff_red = litavg_red - shadowavg_red;
diff_green = litavg_green - shadowavg_green;
diff_blue = litavg_blue - shadowavg_blue;
% adding the difference to the shadow pixels
result(:,:,1) = image(:,:,1) + smoothmask * diff_red;
result(:,:,2) = image(:,:,2) + smoothmask * diff_green;
result(:,:,3) = image(:,:,3) + smoothmask * diff_blue;
elseif strcmp(type, 'basiclightmodel')
% basic, light model based shadow removal
% computing ratio of shadow/lit area luminance
ratio_red = litavg_red/shadowavg_red;
ratio_green = litavg_green/shadowavg_green;
ratio_blue = litavg_blue/shadowavg_blue;
% multipliing the shadow pixels with the raio for the correction
result(:,:,1) = image(:,:,1).*(1-mask) + mask.*ratio_red.*image(:,:,1);
result(:,:,2) = image(:,:,2).*(1-mask) + mask.*ratio_green.*image(:,:,2);
result(:,:,3) = image(:,:,3).*(1-mask) + mask.*ratio_blue.*image(:,:,3);
elseif strcmp(type, 'advancedlightmodel')
% advanced, light model based shadow removal
% computing ratio of the luminances of the directed, and global
% lights
ratio_red = litavg_red/shadowavg_red - 1;
ratio_green = litavg_green/shadowavg_green - 1;
ratio_blue = litavg_blue/shadowavg_blue - 1;
% appliing shadow removal formula
% (too long for the comment -> see documentation :) )
result(:,:,1) = (ratio_red + 1)./((1-smoothmask)*ratio_red +
1).*image(:,:,1);

result(:,:,2) = (ratio_green + 1)./((1-smoothmask)*ratio_green +


1).*image(:,:,2);
result(:,:,3) = (ratio_blue + 1)./((1-smoothmask)*ratio_blue +
1).*image(:,:,3);
elseif strcmp(type, 'ycbcr')
% combined additive and light model based shadow removal in
% ycbcr colourspace
% conversion to ycbcr
ycbcr = rgb2ycbcr(image);
% computing averade channel values in ycbcr space
shadowavg_y = sum(sum(ycbcr(:,:,1).*shadow_core)) /
sum(sum(shadow_core));
shadowavg_cb = sum(sum(ycbcr(:,:,2).*shadow_core)) /
sum(sum(shadow_core));
shadowavg_cr = sum(sum(ycbcr(:,:,3).*shadow_core)) /
sum(sum(shadow_core));
litavg_y = sum(sum(ycbcr(:,:,1).*lit_core)) / sum(sum(lit_core));
litavg_cb = sum(sum(ycbcr(:,:,2).*lit_core)) / sum(sum(lit_core));
litavg_cr = sum(sum(ycbcr(:,:,3).*lit_core)) / sum(sum(lit_core));
% computing ratio, and difference in ycbcr space
diff_y = litavg_y - shadowavg_y;
diff_cb = litavg_cb - shadowavg_cb;
diff_cr = litavg_cr - shadowavg_cr;
ratio_y = litavg_y/shadowavg_y;
ratio_cb = litavg_cb/shadowavg_cb;
ratio_cr = litavg_cr/shadowavg_cr;
% shadow correction, see formulas above
% y channel has an additive correction
% cb, and cr channels gets a model based correction
res_ycbcr = ycbcr;
res_ycbcr(:,:,1) = ycbcr(:,:,1) + mask * diff_y;
res_ycbcr(:,:,2) = ycbcr(:,:,2).*(1-mask) + mask.*ratio_cb.*ycbcr(:,:,2);
res_ycbcr(:,:,3) = ycbcr(:,:,3).*(1-mask) + mask.*ratio_cr.*ycbcr(:,:,3);
% conversion back to rgb colourspace
result = ycbcr2rgb(res_ycbcr);

end

end

CHAPTER 11
BLOCK DIAGRAM (using Fuzzy Divergence technique)

CHAPTER 12

FEATURES OF THE PROJECT

1.De-Shadowing :Removing all the shadow elements completely from the input image.

2.Input Image:Image is in RGB space, with colour values between 0 and 1. The image contains one
homogenious texture, in part in the shadowand in part in the light.

3.Mask :Pixels in the shadow are assigned with the value of 1, pixel in the light are marked with a 0,
and a smooth transition is allowed.

4.Type :This string declared in the MATLAB code helps us indentify the approach to be adopted for
detection and removal of shadows .The methods to choose from are :

Additive Model
Basic Light Model
Advanced Light Model
YCbCr Model

CHAPTER 13
MODULES OF THE PROJECT :13.1.SHADOW DETECTION
To detect shadow initially the RGB image is converted to an LAB equivalent image. The
LAB color space has three channels where L is the Lightness channel, A and B are the two
color channels. The L channel has values ranging from 0 up to 100, which corresponds to
different shades from black to white. The A channel has values ranging from 128 up to
+127 and gives the red to green ratio. The B channel also has values ranging from 128 up to
+127 and gives the yellow to blue ratio. Thus, a high value in A or B channel represents a
color having more red or yellow and a low value represents a color having more green or
blue. Since the shadow regions are darker and less illuminated than the surroundings, it is
easy to locate them in the L channel since the L channel gives lightness information. The B
channel values are also lesser in the shadow areas in most of the outdoor images. Thus
combining the values from L and B channels, the pixels with values less than a threshold are
identified as shadow pixels, and others as non-shadow pixels.
To detect shadow first a RGB image has to be converted to a LAB image. Then the mean
values of the pixels in L, A and B planes of the image have to be computed separately. Now
if mean (A) + mean (B) 256, then the pixels with a value in L (mean (L) standard
deviation (L)/3) can be classified as shadow pixels and others as non-shadow pixels.
Otherwise the pixels with lower values in both L and B planes can be classified as shadow
pixels and others as non-shadow pixels . This pixel-based method may classify some non
shadow pixels as shadow pixels.
Cleaning, a morphological operation can remove isolated pixels. The misclassified pixels are
removed using dilation followed by erosion. Also area-based thresholding is done, so that
only regionswith a number of pixels greater than a threshold can be considered as shadow
regions. All these morphological operations thus help to eliminate misclassification of pixels.

13.1.1Segementation through MASK creation

The mask describes the pixel lightness of the image and hence is used to segregate the
plane into shadow and non-shadow parts on the basis of the gray-level values of the
pixel.

This division created hence helps in identifying and detecting the darker or the
shadow pixels.

In this case it assigns binary values ,such that the pixels in the shadow are assigned
with the value of 1 and pixel in the light are marked with a 0(or vice versa), and a
smooth transition is allowed .

If not given a global thresholding will be used for shadow detection. So in this
manner the entire image is divided into two sections .

Examples of Masks :-

13.2.SHADOW REMOVAL

The first step is to load image with shadow as was preceeded by the shadow removal
phase , which have probably same texture throughout.

Remove pepper and salt noise by applying contra harmonic filter. To remove shadow
properly, average frame is computed to determine effect of shadow in each of the
three dimensions of colour.

So the colours in shadow regions have larger value than the average, while colours in
non-shadow regions have smaller value than the average values. Images are
represented by varying degrees of red, green, and blue (RGB). Red, green, and blue
backgrounds are chosen because these are the colors whose intensities, relative and
absolute, are represented by positive integers up to 255.

Then, construct a threshold piecewise function to extract shadow regions. The results
of the thresholdfunction is a binary bitmap where the pixel has a value of zero if the
corresponding pixel is in the shadow region and it has a value of one if the
corresponding pixel is in the nonshadow region.

Finally, convolute the noise-free binary image with the original image to separate the
shadow from the nonshadow regions. By testing the effects of shadow on specific
pixels located in the solid backgrounds, the effect
of shadow can be derived for different pixel value combinations by applying binary
and morphological function.

Solid colours are utilized as a background in order to remove as many variables as


possible from the experiment. Pixels with wide variations in colour may reside next to
each other giving skewed results.

The separate analyses of these three solid backgrounds showed a correlation utilized
to predict the effect of shadow in a multitude of situations. Finally energy function is
applied to remove shadow.

CHAPTER 14
CONTROL FLOW DIAGRAM

CHAPTER 15
METHOD
15.1Original image

This is the original image which we have considered as an example from which
we want to remove shadow using the shadow removal and detection method
which we have developed. This image will be the input to our module, the final
output of which will an image with the shadow removed.

The method we have developed is applicable to a wide range of images having


different formats like png,tif,jpg,jpeg,etc. The image we have considered here is
of png format.

This is the first step in our method , the subsequent steps will be shown as we
proceed.

15.2Mask

A mask is a black and white image of the same dimensions as the original
image (or the region of interest you are working on). Each of the pixels in the
mask can have therefore a value of 0(black) or 1(white).

When executing operations on the image the mask is used to restrict the result to
the pixels that are 1(selected,active,white) in the mask. In this way operations
restrict to some parts of the image.

The mask describing the pixel lines on the image.(segmentation of the


shadow).pixels in the shadow are assigned with the value of 1,pixel in the light
are marked with 0,and a smooth transition is allowed.

15.3Shadow core

After we construct the mask of the image, a morphological operation called


erosion is performed on the original image with shadow using this mask and a
predefined structuring element.

Erosion can be viewed as a morphological filtering operation in which image


details smaller than the structuring element are filtered from the image. In
equation it is represented as
A B={z|(B)z subset A}
Where A and B are sets in Z2 , A B denotes erosion of A by B and the equation
means that the erosion of A by B is the set of all points z such that B, translated
by z, is contained in A.

Thus, after erosion we get an image which is referred to as shadow core(pixels


not on the blurred edge of the shadow area).

15.4Light core

For obtaining shadow core mask was eroded by a predefined structuring


element. Likewise for obtaining lit core compliment mask is eroded by the same
structuring element. Here erosion process is the same as described for shadow
core.

Shadow core and lit core are used for averaging pixel intensities in the shadow
and light area respectively.

15.5Smooth mask

Smooth mask is an image that is obtained by performing 2-D convolution of


mask and structuring element. This is implemented through function conv2(A,
B, shape). The first parameter is the mask and the second one is the structuring
element. For the third parameter shape, same is used which returns the central
part of convolution that is of the same size as the mask.

Convolution is the process of moving a filter mass over the image and
computing the sum of products at each location except that the filter is first
located by 180. Convolution is used for spatial smoothing of an image.
Smoothing filters are used for blurring a noise reduction. Blurring is used in
preprocessing tasks, such as removal of small details from an image prior to
(large) object extraction, and bridging of small gaps in lines or curve.

15.6Output image
(shadow removed)

Once we have the shadow core, lit core and smooth mask, shadow removal can
be performed using the above through one of the four methods. The four
methods are additive method, basic light model method, advanced light model
method and YCbCr method. Each of these methods uses a unique technique and
has a basic set of steps to proceed.

Though these methods vary in the methodology used, output of all is the same,
original image with the shadow removed from it.

CHAPTER 16
SHADOW REMOVAL METHODS

16.1Additive method

This is rather a simple shadow removal technique in which an additive


correction of the color intensities in shadow area is done.
In this we first compute the average pixel intensities in the shadow and lit
areas of the image. The shadow and lit area of the image are obtained as
shadow core and lit core through a morphological operation called erosion.
Erosion is performed on the mask using the structuring element. The
corresponding equations are

shadow_core = imerode(mask, strel);


lit_core = imerode(1-mask, strel);
The average pixel intensities in the shadow area are computed as

shdwavg_red=sum(sum(image(:,:,1).*shdw_core))/sum(sum(shdw_core));
shdwavg_green=sum(sum(image(:,:,2).*shdw_core))/sum(sum(shdw_core));
shdwavg_blue=sum(sum(image(:,:,3).*shdw_core))/sum(sum(shdw_core));
The average pixel intensities in the light area are computed as

litavg_red=sum(sum(image(:,:,1).*lit_core))/sum(sum(lit_core));
litavg_green=sum(sum(image(:,:,2).*lit_core))/sum(sum(lit_core));
litavg_blue=sum(sum(image(:,:,3).*lit_core))/sum(sum(lit_core));

Then add this difference to the pixels in the shadow areas.

2.YCbCr Method

First we convert the image to YCbCr space--ycbcr = rgb2ycbcr(image);

Then we compute the average channel values, differences and ratios in ycbcr
space--shdwavg_y = sum(sum(ycbcr(:,:,1).*shdw_core)) / sum(sum(shdw_core));
shdwavg_cb = sum(sum(ycbcr(:,:,2).*shdw_core)) / sum(sum(shdw_core));
shdwavg_cr = sum(sum(ycbcr(:,:,3).*shdw_core)) / sum(sum(shdw_core));
litavg_y = sum(sum(ycbcr(:,:,1).*lit_core)) / sum(sum(lit_core));
litavg_cb = sum(sum(ycbcr(:,:,2).*lit_core)) / sum(sum(lit_core));
litavg_cr = sum(sum(ycbcr(:,:,3).*lit_core)) / sum(sum(lit_core));
diff_y = litavg_y - shadowavg_y;
diff_cb = litavg_cb - shadowavg_cb;
diff_cr = litavg_cr - shadowavg_cr;
ratio_y = litavg_y/shadowavg_y;
ratio_cb = litavg_cb/shadowavg_cb;
ratio_cr = litavg_cr/shadowavg_cr;

Next we use additive method for correction on Y channe and mode based
correction on cb and cr channel--res_ycbcr = ycbcr;
res_ycbcr(:,:,1) = ycbcr(:,:,1) + mask * diff_y;
res_ycbcr(:,:,2) = ycbcr(:,:,2).*(1-mask) + mask.*ratio_cb.*ycbcr(:,:,2);
res_ycbcr(:,:,3) = ycbcr(:,:,3).*(1-mask) + mask.*ratio_cr.*ycbcr(:,:,3);

16.3.Basic and Advanced Light based Method

We use a simple shadow model, where there are two types of light sources:
direct and ambient light .
Direct light comes directly from the source, while environment light is from
reflections of surrounding surfaces. For shadow areas part or all of the direct
light is occluded. The shadow model can be represented by following formula:
Li = (TiCosiLd+Le)Ri
Li represents the value for the i-th pixel in RGB space .
Ld and Le represent the intensity of the direct light and environment light, also
measured in RGB space .
Ri is the surface reflectance of that pixel
i is the angle between the direct lighting direction and the surface norm
Ti is the attenuation factor of the direct light; if Ti=1 means the object point is
in a sunshine region; if Ti =0 then the object point is in a shadow region
We denoted by Ki= TiCosi the shadow coefficient for the i-th pixel and by
r=Ld/Le the ratio between direct light and environment light.
Based on this model, our goal is to relight each pixel using this
coefficient in order to obtain a shadow free image. The new pixel value is
computed based on the model .

CHAPTER 17
CONCLUSION

In this work, we have presented a simple algorithm for accurate, fully automatic,
shadow detection and subsequent removal in images . It is based on increasing the
regulated lightness of shadowed regions in an image by replication of colours in
relation to neighbors of that pixel(Mean/Median Methods).

The color of that part of the surface is then corrected so that it matches the lit part of
the surface. It is also observed that The image can be segmented successfully into
segments based on colors and gray scale values alone alone. This shows that it is
possible to remove shadow from image without losing a large amount of pertinent
data.

The ability to correct shadow regions depends on an accurate and effective strategy of
both detecting shadow and de-shadowing, both of which are fundamentally important
to our conception and understanding of producing a shadow-free image.

The commonly used shadow detection techniques and de-shadowing methods in the
shadow correction procedure are thresholding and recovery information in shadow,
respectively. There is a need for classification of various algorithms that have been
employed in shadow correction research to allow greater understanding of their
disadvantages and advantages.

Also, by increasing the amount of sensed data, particularly new data, there is a need to
develop new shadow correction algorithms. In addition, a standard shadow correction
tool should be added to photo editing software applications.

CHAPTER 18
Referrences

Digital Image Processing By Rafael C. Gonzalez and Richard E. Woods.

Shadow detection and removal in colour images using matlab- International Journal
of Engineering Science and Technology .

MATLAB teaching code guide MIT.

Image Processing Kenneth .R .Castleman .

MATLAB Programming Y.Kiryani Singh.

MathWorks Book Program- MATLAB and simulink.

You might also like