CG 5
CG 5
&
IMAGE PROCESSING
MODULE 5
Namitha Ramachandran
Basic gray level transformation functions
Enhancing an image provides better contrast and a more detailed image as compared
to non enhanced image.
The transformation function has been given below
S=T(r)
where r is the pixels of the input image and s is the pixels of the output image. T is a
transformation function that maps each value of r to each value of s.
Image enhancement can be done through gray level transformations
There are three basic gray level transformation.
•Linear
•Log Transformation
•Power – law Transformation Namitha Ramachandran
Linear transformation
First, we will look at the linear transformation. The linear transformation includes
simple identity and negative transformation.
Identity transition
In this transition, each value of the input image is directly mapped to the
other value of the output image.
That results in the same input image and output image.
Namitha Ramachandran
Negative transformation
The second linear transformation is negative transformation, which is an invert of
identity transformation.
In negative transformation, each value of the input image is subtracted from the L-1
and mapped onto the output image.
In this the following transition has been don
s = (L – 1) – r
since the input image of Einstein is an
Input Image 8 bpp image,
so the number of levels in this image
are 256.
Putting 256 in the equation,
we get
s = 255 – r
Namitha Ramachandran
Logarithmic transformations
Logarithmic transformation further contains two types of transformation.
Log transformation and inverse log transformation.
Where s and r are the pixel values of the output and the input image and c is a
constant.
The value 1 is added to each of the pixel value of the input image because if there is
a pixel intensity of 0 in the image, then log (0) is equal to infinity.
Namitha Ramachandran
Wider Output Range
Region unaffected
Namitha Ramachandran
Narrow Input Range
Inverse log transformation
The inverse log transform is opposite to the log transform.
Namitha Ramachandran
Narrow Output Range
Namitha Ramachandran
Wider Input Range
Power–Law (Gamma) transformations
Power Law Transformation is of two types of transformation nth
power transformation and nth root transformation.
s=cr^γ
Variation in the value of γ varies the enhancement of the images. C is constant.
Different display devices / monitors have their own gamma correction, that’s why they
display their image at different intensity.
This type of transformation is used for enhancing images for a different types of display
devices. (Gamma Correction)
The gamma of different display devices is different.
For example, Gamma of CRT lies in between 1.8 to 2.5, Namitha Ramachandran
Power-law transformation is similar to log transformation, but for different gamma,
value output will be different contrast images.
Namitha Ramachandran
Namitha Ramachandran
COMPUTER GRAPHICS
&
IMAGE PROCESSING
MODULE 5
CONTRAST STRETCHING
Namitha Ramachandran
18
Piece-wise Linear Transformation
Piece-wise Linear Transformation is type of gray level
transformation that is used for image enhancement.
Namitha Ramachandran
If slope=1 ,output image=input image
Slope=z
d
If slope>1 , output image is brighter than
the input image
x .r , 0<= r <=a
c Slope=x
S= y.(r-a) +c, a<r<=b
a b
z.(r-b)+d , b<r<=L-1
Namitha Ramachandran
Intensity Level slicing
This technique is used to highlight a specific range of gray levels in a given image
(thresholding).
One approach is to display a high value for all gray levels in the range of interest
and a low value for all other gray levels.
The second approach, based on the transformation brightens the desired range of
gray levels but preserves gray levels unchanged. Namitha Ramachandran
Namitha Ramachandran
COMPUTER GRAPHICS
&
IMAGE PROCESSING
MODULE 5
Histogram processing
Histogram Equalization
Namitha Ramachandran
26
Histogram Processing
In digital image processing, the histogram is used for the graphical
representation of a digital image.
Namitha Ramachandran
Applications of Histograms
It is used to analyze an image. Properties of an image can be predicted
by the detailed study of the histogram.
The brightness of the image can be adjusted by having the details of
its histogram.
The contrast of the image can be adjusted according to the need by
having details of the x-axis of a histogram.
It is used for image equalization. Gray level intensities are expanded
along the x-axis to produce a high contrast image.
Histograms are used in thresholding as it improves the appearance of
the image.
If we have input and output histogram of an image, we can determine
which type of transformation is applied in the algorithm.Namitha Ramachandran
Histogram Equalisation
Histogram Equalization is a computer image processing technique used
to improve contrast in images.
Input image
Step 1
Gray 0 1 2 3 4 5 6 7
levels(rk)
No. of 0 8 8 2 0 7 0 0
pixels(nk)
Namitha Ramachandran
Gray 0 1 2 3 4 5 6 7
levels(rk)
No. of 0 8 8 2 0 7 0 0
pixels(nk)
Step 2: Histogram of input image
6
No of 5
pixels
(nk) 4
3
2
1
0 1 2 3 4 5 6 7 Namitha Ramachandran
Gray levels(rk)
Step 3
Gray levels No.of pixels Probability Density Sk Sk HG
(rk) (nk) Function(PDF)(P(rk)=nk/n) (cumulative Distribution x Sk x7 Equalized
Function-CDF) max.gray level levels
0 0 0 0 0 0
1 8 0.32 0.32 2.24 2
2 8 0.32 0.64 4.48 4
3 2 0.08 0.72 5.04 5
4 0 0 0.72 5.04 5
5 7 0.28 1 7 7
6 0 0 1 7 7
7 0 0 1 7 7
Max.gray n=25
level
Namitha Ramachandran
Gray levels No.of pixels Probability Distribution Sk Sk HG
(rk) (nk) Function(PDF)(P(rk)=nk/n (cumulative Distribution x Sk x7 Equalized
Function-CDF) max.gray level levels
0 0 0 0 0 0
1 8 0.32 0.32 2.24 2
2 8 0.32 0.64 4.48 4
3 2 0.08 0.72 5.04 5
4 0 0 0.72 5.04 5
5 7 0.28 1 7 7
6 0 0 1 7 7
7 0 0 1 7 7
Max.gray n=25
level
Namitha Ramachandran
2 4 2 2 2
1 2 1 1 1
4 7 5 7 4
2 5 3 5 2
4 7 7 7 4
2 5 5 5 2 F(x,y)=
4 7 5 7 4
F(x,y)=
2 5 3 5 2
2 2 2 4 2
1 1 1 2 1
Output image
Input image
Namitha Ramachandran
Gray levels No.of pixels Probability Distribution Sk Sk HG
(rk) (nk) Function(PDF)(P(rk)=nk/n (cumulative Distribution x Sk x7 Equalized
Function-CDF) max.gray level levels
0 0 0 0 0 0
1 8 0.32 0.32 2.24 2
2 8 0.32 0.64 4.48 4
3 2 0.08 0.72 5.04 5
4 0 0 0.72 5.04 5
5 7 0.28 1 7 7
6 0 0 1 7 7
7 0 0 1 7 7
Max.gray n=25
level
Namitha Ramachandran
Step 4
Gray 0 2 4 5 7
Levels
No.of 0 8 8 2 7
pixels
6
No of 5
pixels
(nk) 4
3
2
1
0 1 2 3 4 5 6 7 Namitha Ramachandran
Gray levels(rk)
Perform histogram equalisation on the following image its gray
level distribution is given
Gray 0 1 2 3 4 5 6 7
Level(rk)
No.of 8 10 10 2 12 16 4 2
pixels (nk)
Namitha Ramachandran
14
Gray 0 1 2 3 4 5 6 7
13 Level(r
12 k)
No.of 8 10 10 2 12 16 4 2
11 pixels
(nk)
10
5
4
3
2
1
0 1 2 3 4 5 6 7 Namitha Ramachandran
Gray levels(rk)
Gray levels No.of pixels Probability Distribution Sk Sk HG
(rk) (nk) Function(PDF)(P(rk)=nk/n (cumulative Distribution x Sk x7 Equalized
Function-CDF) max.gray level levels
0 8 0.125 0.125 0.875 1
1 10 0.15625 0.28125 1.96875 2
2 10 0.15625 0.4375 3.0625 3
3 2 0.03125 0.46875 3.28125 3
4 12 0.1875 0.65625 4.59375 5
5 16 0.25 0.90625 6.34375 6
6 4 0.0625 0.96875 6.78125 7
7 2 0.03125 1 7 7
Max.gray n=64
level
Namitha Ramachandran
Gray 1 2 3 5 6 7
Levels
No.of 8 10 12 12 16 6
pixels
Namitha Ramachandran
14
Gray Levels 1 2 3 5 6 7
13
12 No.of pixels 8 10 12 12 16 6
11
10
5
4
3
2
1
0 1 2 3 4 5 6 7 Namitha Ramachandran
Gray levels(rk)
Steps Involved in Histogram Equalisation
1 2 1 1 1
2 5 3 5 2 For an image segment like this ,maximum intensity used is 5 here,so
gray levels ranging from 0 to 7 ,because this range include 5 .
2 5 5 5 2
2 5 3 5 2
1 1 1 2 1
Namitha Ramachandran
3. Histogram of Input image
Plot the histogram of input image based on gray levels and corresponding frequency
values.
4. Evaluate PDF -Probability Density Function (Normalising in the
range of 0-1)
Use the formula P(rk)=nk/n
Where nk=frequency of gray level , n= maximum gray level value
𝑠 𝑘 = 𝑇 𝑟𝑘 = Pr 𝑟𝑗 , 𝑘 = 0,1, . . 𝐿 − 1
Namitha Ramachandran
𝑗=0
6. Multiply each cumulative value using the maximum gray value
in the above example gray levels ranging from 0…7, the maximum gray value is 7 (say n)
n xSK
8. Using the histogram equalized gray levels and the frequency value
plot the histogram of the output image.
Namitha Ramachandran
The response ‘R’ to the template is:
Namitha Ramachandran
Smoothing Linear Filters
Image smoothing is a digital image processing technique that reduces and suppresses
image noises, also used for image blurring.
In the spatial domain, neighborhood averaging can generally be used to achieve the
purpose of smoothing.
The idea is to replace the value of every pixel in an image by the average of the
intensity levels in the neighbourhood defined by the filter mask.
Edges are an important part of an image, applying average filters has undesirable side
effects of blurring an image.
Namitha Ramachandran
Namitha Ramachandran
A spatial average filter in which all the coefficients are equal is known as box filters .
Namitha Ramachandran
20 30 50 80 100
Apply standard average filter for pixel at (3,3)
30 20 80 100 100
40 30 70 40 100
1 1 1
50 60 80 30 90
1 1 1
1 1 1
1/9 [20x1+80x1+100x1+30x1+60x1+10x1+30x1+70x1+40x1]
Namitha Ramachandran
Apply standard average filter for pixel at (1,1)
0 0 0 0 0 0
0 30 20 80 100 100
1 1 1
0 20 30 60 10 110
1 1 1
0 40 30 70 40 100
1 1 1
0 50 60 80 30 90
1/9 [0x1+0x1+0x1+0x1+20x1+30x1+0x1+30x1+20x1]
Namitha Ramachandran
Apply standard average filter for pixel at (2,3)
30 20 80 100 100
1 2 1
20 30 60 10 110
2 4 2
40 30 70 40 100
1 2 1
50 60 80 30 90
1/16 [30x1+50x2+80x1+20x2+80x4+100x2+30x1+60x2+10x1]
Namitha Ramachandran
Order static(Nonlinear ) smoothing Filters
The response of the filter depends on the ordering or ranking of the pixels in the image.
Replacing the center pixel value with the value determined by the ranking result.
1. Median Filter
The filter replaces the value of a pixel in the image by the median of the gray levels
encompassed by the filter.
Provide excellent noise reduction compared to linear smoothing filters.
Cause less blurring in the image.
Most effective for removing impulse noise (salt and pepper noise).
Namitha Ramachandran
Namitha Ramachandran
Max Filter
To find the brightest points in an image.
Finds the maximum value in the area encompassed by the filter.
Reduces the pepper noise as a result of the max operation.
Namitha Ramachandran
Namitha Ramachandran
MIN Filter
To find the darkest points in an image.
Finds the minimum value in the area encompassed by the filter.
Reduces the salt noise as a result of the min operation.
Namitha Ramachandran
COMPUTER GRAPHICS
&
IMAGE PROCESSING
MODULE 5
Namitha Ramachandran
Namitha Ramachandran
𝝏𝒇
=𝒇 𝒚+𝟏 −𝒇 𝒚
𝛛𝒚
Namitha Ramachandran
Area of constant intensity: both first-order derivatives and second-order derivatives are
zero.
First order derivative nonzero at onset of ramp and step .
The second-order derivative is nonzero at the onset and end of both the ramp and step.
First-order derivative is nonzero and the second is zero along the ramp.
1st derivative detects thick edges while the second derivative detects thin edges.
2nd derivative has a much stronger response at the gray-level step than 1st derivative.
Namitha Ramachandran
First Derivative r Filters
Namitha Ramachandran
Gradient in diagonal direction
Edge detection
Edge detection
Namitha Ramachandran
Namitha Ramachandran
Namitha Ramachandran
0 -1 0
-1 4 -1
0 -1 0
-1 -1 -1
-1 8 -1
-1 -1 -1 Namitha Ramachandran
Fundamentals of Image Segmentation.
Image Segmentation is the process by which a digital image is partitioned into
various subgroups (of pixels) called Image Objects, which can reduce the
complexity of the image, and thus analyzing the image becomes simpler.
Similarity Detection (Region Approach)
This fundamental approach relies on detecting similar pixels in an image – based on a
threshold, region growing, region spreading, and region merging so does
classification, which detects similarity based on a pre-defined (known) set of features.
In a simple thresholding technique, a standard threshold value is set and each pixel
value is compared with the threshold value. If the pixel value is less than the
mentioned threshold value then the value is set to 0 or else it is set to the maximum
value.
Namitha Ramachandran
Namitha Ramachandran
Namitha Ramachandran
Global thresholding: T is constant and applicable over the whole image.
Namitha Ramachandran
Basics of Global Thresholding
We have algorithms for estimating automatically the threshold value for each image.
Iterative algorithm
Otsu’s method
Namitha Ramachandran
Namitha Ramachandran
Namitha Ramachandran
COMPUTER GRAPHICS
&
IMAGE PROCESSING
MODULE 5
FUNDAMENTALS OF IMAGE
SEGMENTATION
In the case of the Region growing method, we start with some pixel as the seed pixel
and then check the adjacent pixels.
If the adjacent pixels abide by the predefined rules, then that pixel is added to the
region of the seed pixel and the following process continues till there is no similarity
left. This method follows the bottom-up approach.
For example: Consider a seed pixel of 2 in the given image and a threshold value
of 3, if a pixel has a value less than 3 then it will be considered inside the seed
pixel region. Otherwise, it will be considered in another region.
Hence 2 regions are formed in the following image based on a threshold value of 3.
Namitha Ramachandran
Namitha Ramachandran
Region Splitting and Merging Technique
In Region splitting, the whole image is first taken as a single region. If the region does
not follow the predefined rules, then it is further divided into multiple regions (usually
4 quadrants) and then the predefined rules are carried out on those regions in order to
decide whether to further subdivide or to classify that as a region. The following
process continues till there is no further division of regions required i.e every region
follows the predefined rules.
Namitha Ramachandran
Usually, first region splitting is done on an image so as to split an image into
maximum regions, and then these regions are merged in order to form a good
segmented image of the original .
Apply region splitting on the following image. Assume the threshold value be<=4.
5 4 5 4 2 3 4 6
0 3 2 3 3 2 4 7
R4 0 0 0 0 2 2 5 6
R3
1 1 0 1 0 3 4 4
1 0 1 0 2 3 5 4 Namitha Ramachandran
Higher value-Lower value>4 then split
R1
5 6 6 6 7 7 6 6
R1 R2
6 7 6 7 5 5 4 7
6 6 4 4 3 2 5 6
5 4 5 4 2 3 4 6
0 3 2 3 3 2 4 7
R4 0 0 0 0 2 2 5 6
R3
1 1 0 1 0 3 4 4
1 0 1 0 2 3 5 4 Namitha Ramachandran
Higher value-Lower value>4 then split
R2
7-2=5>4 ,split
R21 R22
5 6 6 6 7 7 6 6 R21
R1 7-5=2<=4 ,NO split
6 7 6 7 5 5 4 7 R2
R22
6 6 4 4 3 2 5 6
R24 7-4=3<=4 ,NO split
5 4 5 4 2 3 4 6 R23 R23
0 3 2 3 3 2 4 7 6-4=2<=4 ,NO split
R24
R4 0 0 0 0 2 2 5 6
3-2=1<=4 ,NO split
R3
1 1 0 1 0 3 4 4
1 0 1 0 2 3 5 4 Namitha Ramachandran
Higher value-Lower value>4 then split
R3
7-0=7>4 ,split
R21 R22
5 6 6 6 7 7 6 6 R31
R1 3-2=1<=4 ,NO split
6 7 6 7 5 5 4 7 R2
R32
6 6 4 4 3 2 5 6
R24 6-4=3<=4 ,NO split
5 4 5 4 2 3 4 6 R23 R33
0 3 2 3 3 2 4 7 5-4=1<=4 ,NO split
R31 R32
R34
R4 0 0 0 0 2 2 5 6
3-0=3<=4 ,NO split
1 1 0 1 0 3 4 4
R33
1 0 1 0 2 3 5 4 Namitha Ramachandran
R34
Higher value-Lower value>4 then split
R4
6 6 4 4 3 2 5 6
R24
5 4 5 4 2 3 4 6 R23
0 3 2 3 3 2 4 7 R32
R31
R4 0 0 0 0 2 2 5 6
1 1 0 1 0 3 4 4
R33
1 0 1 0 2 3 5 4 Namitha Ramachandran
R34
Merging Higher value-Lower value>4 then split
1 1 0 1 0 3 4 4
R33
1 0 1 0 2 3 5 4 Namitha Ramachandran
R34
Merging Higher value-Lower value>4 then split
R21 R22
5 6 6 6 7 7 6 6
R1 R2
6 7 6 7 5 5 4 7
6 6 4 4 3 2 5 6
R24
5 4 5 4 2 3 4 6 R23
0 3 2 3 3 2 4 7 R32
R31
R4 0 0 0 0 2 2 5 6
1 1 0 1 0 3 4 4
R33
1 0 1 0 2 3 5 4 Namitha Ramachandran
R34
Merging Higher value-Lower value>4 then split
R21 R22
5 6 6 6 7 7 6 6
R1 R2
6 7 6 7 5 5 4 7
6 6 4 4 3 2 5 6
R24
5 4 5 4 2 3 4 6 R23
0 3 2 3 3 2 4 7 R32
R31
R4 0 0 0 0 2 2 5 6
1 1 0 1 0 3 4 4
R33
1 0 1 0 2 3 5 4 Namitha Ramachandran
R34
Merging Higher value-Lower value>4 then split
6 6 4 4 3 2 5 6
R24
5 4 5 4 2 3 4 6 R23
0 3 2 3 3 2 4 7 R32
R31
R4 0 0 0 0 2 2 5 6
1 1 0 1 0 3 4 4
R33
1 0 1 0 2 3 5 4 Namitha Ramachandran
R34
Merging Higher value-Lower value>4 then split
Repeat the same with all other regions and finally we get 2 regions
R21 R22
5 6 6 6 7 7 6 6
R1 R2
6 7 6 7 5 5 4 7
6 6 4 4 3 2 5 6
R24
5 4 5 4 2 3 4 6 R23
0 3 2 3 3 2 4 7 R32
R31
0 0 0 0 2 2 5 6
R4
1 1 0 1 0 3 4 4
R33
1 0 1 0 2 3 5 4 Namitha Ramachandran
R34
Edge Detection - Edge Operators- Sobel and Prewitt
With the help of edges and lines, an object’s structure is known. That is why
extracting the edges is a very important technique in graphics processing and feature
extraction.
Namitha Ramachandran
Sobel Edge Detection Operator
The Sobel edge detection operator extracts all the edges of an image, without
worrying about the directions. The main advantage of the Sobel operator is that it
provides differencing and smoothing effect.
Sobel edge detection operator is implemented as the sum of two directional
edges. And the resulting image is a unidirectional outline in the original image.
Namitha Ramachandran
Following is the gradient magnitude:
Namitha Ramachandran
Advantages
Limitations:
Highly sensitive to noise
Not very accurate in edge detection
Detect with thick and rough edges does not give appropriate results
Diagonal direction points are not preserved always
Namitha Ramachandran
Prewitt operator
This operator is almost similar to the sobel operator. It also detects vertical and
horizontal edges of an image. It is one of the best ways to detect the orientation
and magnitude of an image.
Advantages:
Namitha Ramachandran
Robert's cross operator
Advantages:
Detection of edges and orientation is very easy
Diagonal direction points are preserved
Limitations:
Very sensitive to noise
Not very accurate in edge detection Namitha Ramachandran