0% found this document useful (0 votes)
72 views

DIP Unit 2 (Enhancement, Binary, Colour)

This document provides an overview of various image enhancement techniques that can be applied in the spatial domain. It discusses point processing operations like digital negative, contrast stretching, thresholding, and bit plane slicing. It also covers neighborhood processing techniques such as mean filtering, median filtering, high-pass filtering, high-boost filtering, and unsharp masking for noise removal and edge enhancement. Other topics include histogram processing operations like histogram equalization for contrast adjustment and interpolation methods for image zooming.

Uploaded by

Shubham Dhundale
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

DIP Unit 2 (Enhancement, Binary, Colour)

This document provides an overview of various image enhancement techniques that can be applied in the spatial domain. It discusses point processing operations like digital negative, contrast stretching, thresholding, and bit plane slicing. It also covers neighborhood processing techniques such as mean filtering, median filtering, high-pass filtering, high-boost filtering, and unsharp masking for noise removal and edge enhancement. Other topics include histogram processing operations like histogram equalization for contrast adjustment and interpolation methods for image zooming.

Uploaded by

Shubham Dhundale
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 126

Digital Image Processing

UNIT - 2

TYBSC Sem – VI
Lecturer - Dhawal S. Bhangale
IMAGE ENHANCEMENT IN
SPATIAL DOMAIN
Spatial domain
• Means working with pixel values, working
directly with the raw data.
• The modified image
can be expressed as,
g( x , y ) = T [ f( x , y ) ]
where T is the
Transformation applied
• Spatial domain transformations are carried out in
2 ways:
Point processing, Neighborhood processing.
• Point Processing:- Work with single pixel.
T is 1 X 1 operator.
• Identity transform; in this
the original image
don’t change. Modified Gray
Level
(output pixel
value) s

Original Gray Level (input pixel value) r


• Point processing operations:-
• Digital Negative:-
• Inverting the gray levels. Used in displaying X-ray
images.
• Digital negative transform given by;
• S= ( L – 1 ) – r ……. L is number of gray levels (generally 256)
• So when r=0, s=255 & r=255, s=0

• Contrast Stretching:-
• We may get low contrast images due to poor
illumination or wrong setting of lens aperture.
Contrast stretching is Making dark portion darker
and bright portion brighter.
• It increases the dynamic range of modified image.
• Formula for contrast stretching is;

• Where l, m and n are slopes. And


• l , n < 1 and m > 1
• Thresholding:-
• Extreme contrast stretching yields Thresholding.
• i.e. if r1=r2 and s1=0 and s2=L-1.
• Gray Level Slicing:- Used to highlight a specific
range of gray values. This can help identify flaws
in X-rays and CAT scans.
• There are two methods;
1. slicing without background
2. Slicing with Background
• Bit plane slicing:-
• We can find out contribution made by each bit in
an image.
• for an 8-bit image we have 8 bit planes
• These bit planes ranging from bit-plane 0 (least
significant plane) to bit plane 7 (most significant
plane). (i.e. 8 images) showing importance of
each bit in the original image. Can be used for
image compression and steganography.

• Higher-order bits (especially the top four) contain


the majority of the visually significant data. The
other bit planes contribute to more subtle details
in the image.
• Dynamic range compression (log
transformation):- s = c log (1 + r)
• Where, c = 255/(log(1 + max_input_pixel_value)) and 1 is added
to r because, log(0) is infinity.
• Sometimes in an original image the difference
between the highest pixel value and the lowest
pixel value (Dynamic Range) is huge. Due to this
pixels with low values look obscured. E.g. in day
time we cant see stars even though they are
there. The opposite is also true.
• Expands the dark pixels in the image while
compressing the brighter pixels and Compresses
the dynamic range
• Clearly, the low intensity values in the input
image are mapped to a wider range of output
levels. The opposite is true for the higher values.
Image
Negatives,
power-Law
&
Log
Transforma
tions
• Power Law transformation (gamma correction):-
• S = C rγ
C and γ (gamma correction factor) are positive
constants
Magnetic resonance (MR)
image of a fractured
human spine.

C=1 and =0.6

C=1 and =0.3

Original

C=1 and =0.4


• Neighborhood Processing:-
• In this method, we change the value of pixel f(x,y)
based on the values of its 8 neighbors.
• We will calculate g(x,y) and put it in the center
place. Then the mask moves to next pixel.
• What are frequencies in an image?
LOW
FREQUENCY

HIGH
FREQUENCY

LOW
FREQUENCY

• if the gray levels change very rapidly frequency of


that image region is high, and vice versa.
• Image background  low freq.; edges  high freq.
• Image Noise
• During image acquisition and transmission noise
gets added.
• Two types;
– Gaussian Noise
– Salt and Pepper Noise
• 1. Gaussian Noise:-
• Arise during acquisition, poor illumination, high
temperature, electronic circuit noise

• Can be removed using mean filter, median filter,


Gaussian smoothing filter.
• 2. Salt and Pepper Noise:-
• Impulse / speckle noise.
• Sparsely occurring white and black pixels.
• Can be caused due to sharp and sudden
disturbances in the image signal.
• Can be removed using
median filter,
morphological filter.
• Low Pass Filtering
• Low pass averaging filter/mean Filter:-
• Can be used to remove Gaussian noise. It
achieves filtering by blurring the noise.
• Frequency response & spatial response.
• For averaging mask, all coefficients are positive.
Mask idea is to replace every pixel value in an
image by the average of the gray levels in the
neighborhood, this process reduces the sharp
transitions in gray levels.
• we can notice that the edges are blur now, and
sudden transition from value 10 to 50 is reduced
to 10 to 23.3 then to 36.6 and then to 50.
• Some other masks are also useful.

• Using second type of mask is called weighted


averaging.
abc
def

(a) Original image; (b)–(f) Results of smoothing


with square averaging filter masks of sizes n=3, 5,
9, 15, and 35, respectively
• Limitations of Low Pass Filter or Mean Filter or
Averaging Filter:
– Averaging operation leads to the blurring of an image.

– averaging operation attenuates and diffuses impulse


noise in the image but can’t remove.

– A single pixel, with a very unrepresentative value can


affect the mean value of all the pixels in its
neighborhood significantly.
• Low pass median filter:-
• Replaces the value of a pixel by the median of the
neighborhood.
• Median filters are particularly effective in the
presence of impulse noise, also called salt-and-
pepper noise.
• e.g.

Step1: Step2:
Step3: Step4:
median filter
• Highpass Filtering
• Eliminates low frequency regions and enhance
high frequency region. Effect of applying this filter
on image may result in removal of background
and enhancement of fine details and edges.
• So it is also used to sharpen images.
• Consider this image with a sharp edge. If we
apply above mask on this image output will be;

• We can observe 1) negative value which are


invalid, 2) very high value of pixels that can not be
displayed.
• By setting all negative value to 0 we an solve 1st
issue. And to remove 2nd issue we can use a
scaling component in the mask which will scale
down the pixel value to realizable value.
• High-Boost Filtering:-
• In highpass filtering we may get rid of complete
background of image. In case we want to enhance
edges and don’t want the loss of background we
can go for high boost filtering.

• High pass = original – low pass


• fsharp (x,y)= f(x,y) – flow (x,y)
• To get high boost image we change;
• fhb (x,y)= A . f(x,y) – flow (x,y)
• fhb (x,y)= ( A – 1 ) . f(x,y) + f(x,y) - flow (x,y)

• fhb (x,y)= ( A – 1 ) . f(x,y) + fsharp (x,y)

• High boost = ( A – 1 ) . original + high pass


High pass filtered image.


• High boosted image
• Unsharp Masking: We can also get a sharp
image by subtracting a blurred version of image
from original image. Used for edge enhancement.
• Steps are given below:
– Blur filter the image
– Subtract blurred image from original image
– Multiply the result with some weight
– Add result obtained to the original image
• f’(m,n) = f(m,n) + [f(m,n) – ̿f (m,n)]
– f(m,n) – original image
– ̿f (m,n) – blurred version
– f‘(m,n) – sharped result
• Zooming
• Can be done by two methods;
– Replication, Interpolation
• Replication:-
• Simply replicating each row and column.
• This is very easy method of zooming, but if the
image is zoomed to larger sizes clusters of gray
levels are formed, making the image look patchy.
• Original image Zoomed image
• Linear Interpolation:-
• Average of two adjacent pixels along the row is
taken and placed between those pixels, same
operation is performed along the columns.
• Interpolation along rows;
v-row(m,n) = u(m,n); 0<=m<=M-1, 0<=n<=N-1
v-row(m,n+1) = ½{u(m,n) + u(m,n+1)}
0<=m<=M-1, 0<=n<=N-1
Interpolation along columns;
v-col(m,n) = u(m,n); 0<=m<=M-1, 0<=n<=N-1
v-col(m,n+1) = ½{u(m,n) + u(m+1,n)}
0<=m<=M-1, 0<=n<=N-1
Histogram
• It is a plot of the number of occurrences of gray
levels in the image against the gray-level values.
• provides more insight about image contrast and
brightness.
– The histogram of a dark image will be clustered
towards the lower gray level.
– The histogram of a bright image will be clustered
towards higher gray level.
– For a low-contrast image, the histogram will not be
spread equally, that is, the histogram will be narrow.
– For a high-contrast image, the histogram will have an
equal spread in the gray level.
• Histogram Linear Stretching
• We do not alter the basic shape of the histogram,
but we spread it to cover the entire range.
• New gray level to assign pixels to;
(s-max – s-min)
s = T(r) = (r – r-min) + s-min
(r-max – r-min)
• Where,
• s-max  max gray level of output image
• s-min  min gray level of output image
• r-max  max gray level of input image
• r-min  min gray level of input image
Histogram Equalization
• A perfect image is one which has equal number of
pixels in all its gray levels.
• Equalization is a process that attempts to spread
out the gray levels in an image so that they are
evenly distributed across their range.

• It is a technique where the histogram of the


resultant image is as flat as possible. Histogram
equalization provides more visually pleasing
results across a wider range of images.
• Procedure to Perform Histogram Equalisation

– The maximum pixel value is 5. We need three bit


storage. So eight possible gray levels from 0 to 7. The
histogram of the input image is given below:
• Step 1 Compute the running sum of histogram values.

• Step 2 Divide the running sum obtained in Step 1 by the


total number of pixels. In this case, the total number of
pixels is 25.
• Step 3 Multiply the result obtained in Step 2 by the
maximum gray-level value, which is 7 in this case.
• Step 4 Mapping of gray
level by a one-to-one
correspondence:

• The original image and the histogram equalised image


are shown side by side.
• Lets take an example;
• Equalize following Histogram:
• For Home Work:
IMAGE ARITHMETIC
• Image Addition
• Used to create double exposure. Superimposing
one image upon another.
• c (m, n) = f (m, n) + g (m, n)
• e.g. if we have captured 2 images of the same location on same
date and time and 1 image have some noise then that part can
be compensated from other image through image addition.
• Image Subtraction
• Used to find the changes between two images of
a same scene.
• c (m, n) = f (m, n) − g (m, n)
• Image subtraction can be used to remove certain
features in the image.
• Image Multiplication
• Image multiplication is basically used for masking.
Used for background suppression.
• To extract an area from an image, that area can
be multiplied by one and the rest part by zero.
• Image Division
• Dividing the pixels in one image by the
corresponding pixels in a second image is
commonly used in transformation.
• The result of image division is just opposite to
that of image multiplication.
• Alpha Blending
• Alpha blending refers to addition of two images,
each with 0 to 1 fractional masking weights.
Alpha blending is useful for transparency and
compositing(the process of combining multiple images to
form a single image).
• If a and b are two images and c is output image,
• c = (1−α) a + αb
• α is the user-defined value.
• Different values of the variable α will increase the
emphasis on the image a or image b.
• Image a image b
• c = (1-1)a + b …. (=1) c = (1-0.001)a + b …(=0.001)

• c = (1-0.2)a + b …. (=0.2) c = (1-0.7)a + b …(=0.7)


IMAGE ENHANCEMENT IN
FREQUENCY DOMAIN
• Image of a damaged IC chip
• 2nd image shows its Fourier
transform.
• Brightness at the center
indicates image with more low
frequency components.
Diagonal lines indicate
existence of sharp edges
diagonally in original image.
• We should remember center of
DFT represents low frequency
components and peripheries
represents high frequency
components
• Bcoz a Fourier transform is perfectly reversible, if
we compute the DFT of image, and then
immediately inverse transform the result, we can
regain the same image.
• But, if we compute the DFT of image, and then
accentuate certain frequency components and
attenuate others by multiplying Fourier
coefficients by suitable weights. The
corresponding changes in the spatial form can be
seen after an inverse transform is computed. This
is called as Fourier filtering or frequency domain
filtering.
LOW PASS frequency domain filters
• Ideal Low Pass Filter (ILPF)
• Simplest filters. Cuts off all high frequency
components from Fourier transform that are at
the distance greater than the specified distance
(cut-off frequency) D0.

• broadly classified into two types:


1. non-separable filter mask, and
2. separable filter mask.
Non-separable Filter Transfer Function

Separable Filter Transfer Function

l
• Ideal filter is not realizable using
physical components, but using
computer programs only.
• Ringing effect in low pass filtering:-

• The reason behind this effect is convolution


theorem. We know,
g(x,y) = f(x,y) * h(x,y) this is equivalent to,
G(k,l) = F(k,l) X H(k,l)
• Now if we again take the IDFT of H(k,l) it causes
oscillations / ripples.

• Hence when h(x,y) is displayed as image it shows


a dominant filtering component at the center and
unwanted concentric components which causes
ringing effect in
output image.
• Butterworth Low Pass Filter (BLPF):-
• Ringing effect of Ideal filter is caused due to sharp
cut-off frequency, to get rid of it we remove sharp
cut-offs in BLPS.
• Transfer function of BLPS is;

• where n is the order of the function (order:- to


calculate current value how many past values are used is
order of function),
as n increases, it tends to behave like ideal filter.
• Filtered using Ideal filter.
With ringing

• Filtered using Butterworth.


No rings visible
• BLPF functions with orders increasing from
n= 1, 2, 5, 20.
• We can observe as order increases ringing effect
appears and also increases.
• Gaussian Low Pass Filter (GLPF):-
• Given by;

• Main advantage of GLPF over BLPF is there is no


ringing effect no matter what filter order we
choose.
High Pass Frequency domain filters
• To enhance edges and abrupt changes in gray
levels in an image high pass filters are used.
• Ideal High Pass Filter (IHPF):-
• Defined by;

• where D0 is cut-off frequency.


• Ideal high pass filters also suffers from the ringing
effect so not suitable in many practical situations.
• Butterworth High Pass Filter (BHPF):-
• Any high pass filter can be calculated as,
• HHBWF(k,l) = 1 – HLBWF(k,l) where LBWF  Low-Pass
Butterworth Filter

• BHPF causes no ringing effect with lower n (order)
values.

• With D0 = 10
Homomorphic Filtering
• An image f(n1,n2) is characterized by two
components;
– The amount of light incident on scene/object
(illumination) :- i(n1,n2)
– Amount of light reflected by the object
(reflection):- r(n1,n2)
• Image f(n1,n2) is formed by;
f(n1,n2) = i(n1,n2) . r(n1,n2)
where 0 < i(n1,n2) < infinity AND
0 < r(n1,n2) < 1; 0 indicates
total absorption and 1 indicates total reflection.

• Illumination contribute to the low frequency and


reflectance contribute to the high frequency.

• To separately work with both these components,


we can take logarithm of input function.

• Taking Fourier transform on both sides, we get


Now applying desired filter function H(k,l),


• How to get back the original image ? (transforming
image from frequency to spatial domain)
– Calculate IDFT of the above expression and for antilog
perform exponential operation.

• Now, The desired enhanced image is,



• As Homomorphic filter is a high pass filter to
decrease contribution of low frequencies and
amplify contribution of high freq.
• we choose YL < 1 and YH > 1.
DIP UNIT 2 CH 2, 3
Binary Image Processing,
Colour Image Processing
• Morphology is the science of appearance,
shape and organization.

• Mathematical morphology is a collection of


non-linear processes which can be applied to
an image to remove details smaller than a
certain reference shape.
BINARISATION
• Binarisation is the process of converting a
grayscale image to a black-and-white image.
• Grayscale image contains a pixel intensity range
of 0 to 255 levels.
• Global thresholding is used to set all pixels
above a defined value to white, and the rest of
the pixels to black.
• It is very important to decide the appropriate
threshold value to binarise the image.
MATHEMATICAL MORPHOLOGY
• Mathematical morphology is based on set theory.
• Morphological operators are based on set theory
operators.
• Black and White colour pixel sets in mathematical
morphology represent objects in an image.
• In morphological operations, black and white
pixels sets in different shapes and sizes are
applied to the image, these shapes are called as
structuring elements.

• Morphological operations are performed by


moving a structuring element over the binary
image pixel by pixel.

• A logical operation is performed on the pixels


covered by the structuring element.
LOGICAL OPERATIONS
• AND, OR operations.

B B B
W B W
B W W
W W W

W W W
W B B
B W B
B B B
• NOT, XOR operation.

W B
B W

W W W
W B B
B W B
B B W
• Logical Opearations
STANDARD BINARY
MORPHOLOGICAL OPERATIONS
• Dilation
• The dilation operation is defined as,

• Where X is original image


• B is structuring element
• is image B rotated about origin and shifted by
z positions.
• Structuring element is smaller in size than image.
• In this process the SE (Structuring Element) is
placed on the image and shifted from left to right
pixel by pixel.
• The process will look for any overlapping similar
pixels between the structuring element and of the
binary image.
• If there exists an overlapping then the pixels
under the center position of the structuring
element will be turned to 1 or black.
• Lets take an example;
• Consider that the SE is
placed first at * position in
image. At this point, there
is no overlapping between
the black squares of B and
the black squares of X;
hence at position * the square will
remain white.
• When positioned at **, 1 black square
of SE is overlapping 1 black square of
image, hence ** position will be
changed to black. This process will
continue till the last pixel of image.
• The dilation is an expansion operator that
enlarges binary objects. Dilation has many uses,
but the major one is bridging gaps in an image.
• Erosion
• Erosion is the counter-process of dilation. If
dilation enlarges an image then erosion shrinks
the image.
• Erosion is defined by;

• This equation states that the outcome element z


is considered only when the structuring element
is a subset or equal to the binary image X.
• the process will look for whether there is a
complete overlap with the structuring element or
not. If there is no complete overlapping then the
image pixel overlapped by the center of the
structuring element will be set white or 0.
• Erosion is a thinning operator that shrinks an
image. By applying erosion to an image, narrow
regions can be eliminated, while wider ones are
thinned.
Original Image

Dilated Image Eroded Image


DILATION & EROSION BASED
OPERATIONS
• Opening
• Where X is an input image and B is a structuring
element.
• Opening smoothes the inside of the object
contour, breaks narrow strips and eliminates thin
portions of the image.
• The opening operation is used to remove noise
and CCD defects in the images.
• Closing
• The closing operation fills the small holes and
gaps.
• It also smoothes contours and maintains shapes
and sizes of objects.
DISTANCE TRANSFORM
• It calculates distance between pixels of an image.

• Distance calculation is useful in medical imaging,


pattern recognition, comparison of binary images,
etc.

• Euclidean distance, city block, chessboard and


Quasi-Euclidean Distance Transform.
Euclidean Distance
City-Block Distance

• This metric measures the path between the pixels


based on a four-connected neighborhood.
Chessboard Distance

• The chessboard distance metric measures the


path between the pixels based on an eight-
connected neighborhood.
Quasi-Euclidean Distance Transform

• The quasi-Euclidean metric measures the total


Euclidean distance along a set of horizontal,
vertical and diagonal line segments
CH 3
COLOUR IMAGE PROCESSING
• Color is the perceptual sensation of light in the
visible range incident upon the retina.
• Different wavelengths of light are perceived as
different colors.
• Frequency of light – Colour
• Amount of light – Intensity
• Light that has a dominant frequency or set of
frequencies is called chromatic.
• Achromatic light has no color and it contributes
only to quantity or intensity.
COLOUR FORMATION

• There are three colour formation processes:


(i) additive process, (ii) subtractive process, and
(iii) pigmentation.

• Additive Colour Formation


• Two colour frequencies and intensities get added.
• This is used in TV screens.
• Subtractive Colour Formation
• When the light is passes through a filter, part of
light or some frequencies of the light gets
absorbed and rest is transmitted.
• Series of filters can be used to get required
results.
• When color slides are projected onto a screen
colors are formed subtractively.
• Colour Formation by Pigmentation
• Pigment particles can reflect, transmit or absorb
the light that reaches them.
• These events determine the color of the light
reflected by the surface.
• Colour formation through pigmentation
• allows one to see colors in a painting.
COLOUR MODEL
• Color models standardize the way to specify a
particular color.
• It also specifies all constructible colours within a
particular model.
• Some popular color models are,
1. RGB
2. CMY
3. HSI
RGB
• RED, GREEN, BLUE
• Used in CRT monitor screens.
• RGB is an additive
color model.
• Magenta = Red + Blue
• Yellow = Red + Green
• Cyan = Blue + Green
CMY
• Cyan, Magenta, Yellow
• Printers commonly employ the CMY model.

• CMY is a subtractive color


model.
• Magenta = White – Green
• Cyan = White – Red
• Yellow = White –Blue
HSI
• Hue, Saturation and Intensity
1. Hue - dominant colour
2. Saturation - relative purity or the amount of
white light mixed with a hue
3. Intensity – brightness
• HSI decouples the intensity information from the
colour, while hue and saturation correspond to
human perception.
• HIS model is useful for developing image
processing algorithms.
• The conversion from RGB space to HSI space is
given below;

You might also like