0% found this document useful (0 votes)
15 views56 pages

UNIT 2 Image Enhancement in Spatial Domain and Frequency Domain - 2

The document discusses histogram specification in image processing, a technique that transforms an input image to match a desired histogram rather than achieving uniform distribution through equalization. It outlines the derivation of a point operation for this transformation, along with algorithms for histogram matching, image subtraction, and averaging. Additionally, it covers spatial filtering techniques, including smoothing and sharpening filters, and their applications in enhancing image details and reducing noise.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views56 pages

UNIT 2 Image Enhancement in Spatial Domain and Frequency Domain - 2

The document discusses histogram specification in image processing, a technique that transforms an input image to match a desired histogram rather than achieving uniform distribution through equalization. It outlines the derivation of a point operation for this transformation, along with algorithms for histogram matching, image subtraction, and averaging. Additionally, it covers spatial filtering techniques, including smoothing and sharpening filters, and their applications in enhancing image details and reducing noise.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

EC 703:

Image Processing and


Computer Vision

By:
Dr. Hemant S. Goklani
ECE Department
IIIT, Surat
Histogram Specification
(Histogram Matching)

 Histogram equalization yields an image whose pixels are (in


theory) uniformly distributed among all gray levels

 Sometimes, this may not be desirable

 Instead, we may want a transformation that yields an


output image with a pre-specified histogram

 This technique is called histogram specification


Given Information

(1) Input image from which we can compute its histogram .


(2) Desired histogram.

 Goal
 Derive a point operation, H(r), that maps the input
image into an output image that has the user-specified
histogram

 Again, we will assume, for the moment, continuous-


gray values
Approach of derivation

z=H(r) = G-1(v=s=T(r))

Input Uniform Output


image s=T(r) image v=G(z) image
· Suppose, the input image has probability density in p(r) . We
want to find a transformation z = H (r) , such that the probability
density of the new image obtained by this transformation is pout(z)
, which is not necessarily uniform.

· First apply the transformation


r
s  T (r )   pin ( w)dw, 0  r 1
0
This gives an image with a uniform probability density.
· If the desired output image were available, then the following
transformation would generate an image with uniform density:
z
V  G( z )   pout ( w)dw, 0  z 1
0
· From the gray values n we can obtain the gray values z by
using the inverse transformation, z = G-1(v)

· If instead of using the gray values n obtained from (eq-2), we


use the gray values s obtained from (eq-1) above (both are
uniformly distributed ! ), then the point transformation

Z=H(r)= G-1[ v=s =T(r)]

will generate an image with the specified density out p(z) ,


from an input image with density in p(r)
· For discrete gray levels, we have
k
sk  T (rk )   pin (r j ) 0  k  L 1
j 0
k
vk  G( zk )   pout ( z j )  sk 0  k  L 1
j 0

· If the transformation zk ® G(zk) is one-to-one, the inverse


transformation sk ® G-1 (sk) , can be easily determined, since
we are dealing with a small set of discrete gray values.

· In practice, this is not usually the case (i.e., ) zk ® G(zk) is not


one-to-one) and we assign gray values to match the given
histogram, as closely as possible.
Algorithm for histogram specification:
(1) Equalize input image to get an image with uniform
gray values, using the discrete equation:
k
sk  T (rk )   pin (r j ) 0  k  L 1
j 0

(2) Based on desired histogram to get an image with


uniform gray values, using the discrete equation:
k
vk  G( zk )   pout ( z j )  sk 0  k  L 1
j 0
-1 -1
(3) = ® =
z G ( v=s ) z G [T ( r )]
Example: Histogram Matching
Example: Histogram Matching
Arithmetic/logic operations
 Logic operations
 Image subtraction
 Image averaging
Logic operations
 Logic operations: pixel-wise AND, OR, NOT
 The pixel gray level values are taken as string of
binary numbers
Ex. 193 => 11000001

 Use the binary mask to take out the region of


interest(ROI) from an image
Logic operations: example
A B A and B

AND

A or B

OR
Image subtraction
f:original(8 bits) h:4 sig. bits

 Difference image
g(x,y)=f(x,y)-h(x,y)

scaling

difference image
Image subtraction: scaling the
difference image
 g(x,y)=f(x,y)-h(x,y)
 f and h are 8-bit => g(x,y)  [-255, 255]
1. (1)+255 (2) divide by 2
• The result won’t cover [0,255]
2. (1)-min(g) (2) *255/max(g)

Be careful of the dynamic range after the image


is processed.
Image subtraction example:
mask mode radiography
 Inject contrast medium into bloodstream
original (head) difference image
Image averaging
 Noisy image g(x,y)=f(x,y)+η(x,y)
original noise

Clear image Noisy image


 Suppose η(x,y) is uncorrelated and has zero
mean
Image averaging: noise reduction
 Averaging over K noisy images gi(x,y)
K
1
g ( x, y ) 
K
 g ( x, y )
i 1
i

 
E g ( x, y)  f ( x, y)
1 2
 2
g ( x, y )
   ( x, y ) K   2 
K
original Gaussian
noise

averaging averaging
K=8 K=16

averaging averaging
K=64 K=128
Local Enhancement
 Normally, Transformation function based on the
content of an entire image
 Some cases it is necessary to enhance details
over small areas in an image
 The histogram processing techniques are easily
adaptable to local enhancement
Local Enhancement

Pixel-to-pixel translation Nonoverlapping region


Local Equalization
Enhancement Using
Arithmetic/Logic Operations
 Are performed on a pixel-by-pixel basis between two or
more images
 Logic operations are concerned with the ability to
implement the AND, OR, and NOT logic operators
because these three operators are functionally
complete
 Arithmetic operations are concerned about +,-,*, / and
so on (arithmetic operators)
Image Subtraction
 The difference between two images f(x,y) and
h(x,y) expressed as

g(x,y) = f(x,y) – h(x,y)


Image Averaging
 Consider a noisy image g(x,y) formed by the
addition of noise to original image f(x,y)

g ( x, y)  f ( x, y)  ( x, y) where η(x,y) is noise

Where the assumption is that at every pair of


coordinates(x,y) the noise is uncorrelated and has zero
average value.

 The objective of this procedure is to reduce the


noise content.
Image Averaging
 Let there are K different noisy images
 If an image g ( x, y) is formed by averaging K
different noisy images

K
1
g ( x, y ) 
K
 g ( x, y )
i 1
i
Image Averaging (Gray Scale)

1 image

2 5 10 20
images images images images
Image Averaging (Color Image)

(1) (2) (3)

Average image
Spatial filtering
Basics of Spatial Filtering

•Mask, convolution
kernels
•Odd sizes
Spatial Filtering
 Some neighbourhood operation between
neighbourhood of image pixel and corresponding
value of mask/filter/kernel/window that has the
same dimension as the neighbourhood.
 Mask size is M x N and M=2a+1, N=2a+1.
 Modification at border is handled by padding rows
and col. of ‘0’s or by replicating some rows and
columns.
Spatial Filtering
a b
g(x, y)    w(s,t) f (x  s, y  t)
sa tb

a=(m-1)/2 and b=(n-1)/2,


m x n (odd numbers)

For x=0,1,…,M-1 and y=0,1,…,N-1

The basic approach is to sum products between the mask coefficients


and the intensities of the pixels under the mask at a specific location in
the image:
R  w1 z1  w2 z2  ...  w9 z9 (for a 3 x 3 filter)
Neighborhood Averaging
General Spatial Filter
Smoothing Spatial Filters
 Smoothing linear filters: averaging filters, low-pass
filters
 Box filter
 Weighted average
 Order-statistics filters:
 Median-filter: removing salt-and-pepper noise
 Max filter
 Min filter
Smoothing Spatial Filters

 Average or Low pass filter


 Also called box filter
 Blurring of edges
 Smoothing of false contours
 Blurring can be reduced by using weighted average filters.
That is assigning more weight to centre and less weight to
neighbouring pixels
 Image details that are of same size as the filter mask gets
affected considerably
 Jagged borders or edged appears pleasingly smooth
 Generally used to eliminate small objects. That is interest is
gross representation of image. Size of the mask decides
relative size of the object that will be blended with the
background
Smoothing linear filter

Original Image Averaging by Averaging by


1/9*ones(3,3) 1/36*ones(6,6)

A spatial averaging filter that all coefficients are equal is called


box filter
 Mean Filter, Median Filter, Enhancement Filter.
1- These are implemented with convolution masks. Result is some
weighted sum of the values of a pixel and its neighbours. Also
called linear filter.
2- General Prediction.
 If mask coefficients sum to 1 – Average brightness of the image
will be retained.
 If mask coefficients sum to 0 – Resulting image will return a dark
image.
 If coefficients are alternating +ve and –ve – Filter will return edge
information.
 If coefficients are all +ve – filter will blur the image.
Order Static's Filter
 Order statistics filters are nonlinear spatial filters whose response
is based on ordering the pixels contained in the image area
encompassed by the filter, and then replacing the value of the
center pixel with the value determined by the ranking result

 The best known example in this category is median filter. Each


output pixel contains the median value in the m-by-n
neighborhood around the corresponding pixel in the input image
Median Filter
 Median filtering is a nonlinear operation often used in image
processing to reduce "salt and pepper (impulse)" noise.
Median filtering is more effective than convolution when the
goal is to simultaneously reduce noise and preserve edges.

 The principle function of the median filter is to force points


with distinct gray levels to be more like their neighbors.
 For e.g.3*3 neighborhood has values [10 20 20 20 15 20 20 25
100]. These values are sorted as [10 15 20 20 20 20 20 25 100]
which result in a median of 20.
Corrupted by Averaging Using median filter
salt and pepper noise Mask 3*3
Noise density 2%
Sharpening Spatial Filters
 To highlight fine detail in an image or to enhance detail that has
been blurred, either in error or as a natural effect of a particular
method of image acquisition

 Blurring vs Sharpening
 Blurring/smooth is done in spatial domain by pixel
averaging in a neighbors, it is a process of integration

 Sharpening is an inverse process, to find the difference by


the neighborhood, done by spatial differentiation. spatial
differentiation
Sharpening Spatial filters
 Applications:

 Electronic printing
 Medical imaging
 Industrial inspections and
 Autonomous guidance in military systems
Derivative operator
 The strength of the response of a derivative operator is
proportional to the degree of operator is proportional to the
degree of discontinuity of the image at the point at which the
operator is applied

 Image differentiation
 Enhances edges and other discontinuities (noise)

 Deemphasizes area with slowly varying gray-level values


Sharpening – Spatial Differentiation
 Image differentiation enhances edges and noise and
deemphasizes areas with slowly varying gray level values
 Foundation:
 1st and 2nd order derivatives – defined in terms of differences

 Definition for first derivative


 Must be zero – in flat segments
 Must be non zero – at on set of a gray level step or ramp
 Must be non zero – along ramp

 Definition for second derivative


 Must be zero – in flat segments
 Must be non zero – at on set and end of gray level step or ramp
 The shortest distance over which change can occur is between
adjacent pixels
Fundamental of derivatives in image
sharpening

Gray level
profile f

x
δf
δx

x
Sharpening Spatial Filters
 Foundation:
f
 f ( x  1)  f ( x)
x
2 f
 f ( x  1)  f ( x  1)  2 f ( x)
x 2
 Observation

 1st order derivative is nonzero along the entire ramp, while 2nd
order derivative is nonzero only at the onset and end of ramp.
 1st order derivative produce thick edges and 2nd order
derivative much finer ones.
 Response at isolated noise point is much stronger for 2nd order
derivative hence it can enhance fine details much more than
1st order derivative.
 For step change 1st order derivative generally have a stronger
response.
 2nd order derivative produces a double response to a gray level
step (-ve to +ve)
 The second derivative is better suited than the first derivative
for image enhancement because of the ability of the former to
enhance fine detail.
THANK YOU

You might also like