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

IP Unit2

Uploaded by

mchod4461
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)
19 views

IP Unit2

Uploaded by

mchod4461
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/ 64

Image Enhancement and Filter

in Spatial Domain

UNIT 2 | Yuba Raj Devkota


8 hrs | NCCS
Image Enhancement using Spatial Domain
• Image Enhancement is a process that improves the quality of an image for a particular
application. Image enhancement is needed
• To highlight the important details
• To remove noise in the image

Different methods for image enhancement

1. Spatial Domain: Direct Manipulation of pixel values


2. Frequency Domain: Modifying the Fourier Transform of the image. First Spatial domain is
converted to frequency domain using Fourier transform and then inverse transform is applied
to convert back to spatial domain.
3. Combination Method: combination of both Spatial Domain and Frequency Domain.
Basic Gray Level Transformations
• Image enhancement can be done through gray level transformations
• Enhancing an image provides better contrast and a more detailed image as compare to non
enhanced image. Image enhancement has very applications. It is used to enhance medical
images, images captured in remote sensing, images from satellite e.t.c
• 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.
• There are three basic gray level transformation.
1. Linear
2. Logarithmic
3. Power – law
0 represents black
L-1 represents
White
1. Linear transformation (identity & Negative)

• Linear transformation includes simple identity and negative transformation.


• Identity transition is shown by a straight line. In this transition, each value of the input image is
directly mapped to each other value of output image. That results in the same input image and
output image. And hence is called identity transformation.
• It is very less used because same type of image output. If L/4 is mapped (i.e. 256/4), then same
L/4 image is the output. For white image, white image is the output
Negative transformation

• The second linear transformation is negative transformation, which is 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. The result is somewhat like this.
since the input image of Einstein is an 8 bpp image, so the
number of levels in this image are 256. i.e. 2 power 8
Input Image Output Image
Putting 256 in the equation, we get this
s = 255 – r
So each value is subtracted by 255 and the result image
has been shown above. So what happens is that, the
lighter pixels become dark and the darker picture
becomes light. And it results in image negative. It has
been shown in the graph below.

In this case the following transition has been done.


s = (L – 1) – r
Lab 02: Negative Linear Transformation
2. Logarithmic transformations (Log & Inverse Log)
• The log transformations can be defined by this formula
• s = c log(r + 1).
• 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. So 1 is added, to make the minimum value at least 1.
• During log transformation, the dark pixels in an image are expanded as compare to the higher pixel values.
The higher pixel values are kind of compressed in log transformation. This result in following image
enhancement.
• The value of c in the log transform adjust the kind of enhancement you are looking for.

Input Image Log Tranform Image


Log:
For L/4 Input, output is nearly 3L/4, which means that
for less amount of image as input, more amount of image
is the output. That’s why it results in high contrast image.

Inverse Log:

Similarly, for nearly 3L/4 input image, output is L/4 i.e.


for high amount of image, less amount of image is the
output. So it will produce less contrast image.
Lab 03:
Log Transformation
3. Power – Law transformations
• There are further two transformation is power law transformations, that include nth power and nth root
transformation. These transformations can be given by the expression:
s=cr^γ
• This symbol γ is called gamma, due to which this transformation is also known as gamma transformation.
• Variation in the value of γ varies the enhancement of the images. 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 different type of display devices. The gamma of
different display devices is different. For example Gamma of CRT lies in between of 1.8 to 2.5, that means the
image displayed on CRT is dark.

Gamma = 10 Gamma = 8 Gamma = 6


This transformation is similar to log
transformation but different values of gamma

For same input L/4, the output will be different


depending upon the value of gamma.
Lab 04:
Gamma Transformation
Piecewise Linear Transformations
Piece-wise Linear Transformation is type of gray level transformation that is used for image
enhancement. It is a spatial domain method. It is used for manipulation of an image so that the result
is more suitable than the original for a specific application. Some commonly used piece-wise linear
transformations are:
1. Contrast Stretching:
Low contrast image occur often due to improper illumination or non-linearly or small dynamic
range of an imaging sensor. It increases the dynamic range of grey levels in the image. Contrast
Stretching Transform is given by:
In Contrast Stretching, darker images are made more
darker and bright portion are made more brighter.

Contrast stretching (often called normalization) is a


simple image enhancement technique that attempts to
improve the contrast in an image by `stretching' the
range of intensity values it contains to span a desired
range of values, e.g. the the full range of pixel values
that the image type concerned allows.
Almost invisible image is stretched
& in next image, thresholding
2. Grey level slicing: The first approach, shown in first
image, produces high value for
region A to B while remaining region
Highlighting a specific range of grey level in an image.
will be low value. So it produces
• Case-I: binary images.
• To display a high value for all grey levels in the range of interest.
• To display a low value for all grey levels. The second approach, shown in
second image, produces high value
• Case-II: for region A to B while remaining
• Brighten the desired range of grey level. region will be unchanged. So it only
• Preserve the background quality in the range. highlights the region focused, while
others are unchanged.
3. Bit-Plane Slicing
• Bit-plane slicing is a technique used in digital image processing to analyze the individual bits in
the pixel values, where each pixel is represented by a binary number, commonly using 8 bits for
grayscale images or 24 bits for color images. Mostly used in image compression.
• The process of bit-plane slicing involves separating and displaying each bit of the pixel values as a
separate image. It creates a set of binary images, each corresponding to a single bit of the original
pixel values. The most significant bit (MSB) is the leftmost bit, representing the highest order bit;
the least significant bit (LSB) is the rightmost bit, representing the lowest order bit.
1. Convert to binary: Convert the value of each pixel in the image to its binary representation.
2.Bit-plane extraction: The number of planes will equal the number of bits used to represent pixel
values. Each bit is assigned to a separate plane. The MSB is assigned to the first-bit plane and the
LSB to the last-bit plane.
3.Create bit plane images: Create separate images for each extracted bit plane. These images will
be binary, with pixel values of 0 and 1, representing the presence or absence of the corresponding
bit in the original pixel values.
Lab 05: Bit Plane Slicing
Histogram Processing
• In digital image processing, the histogram is used for graphical representation of a digital image. A graph is a
plot by the number of pixels for each tonal value. Nowadays, image histogram is present in digital cameras.
Photographers use them to see the distribution of tones captured.
• In a graph, the horizontal axis of the graph is used to represent tonal variations whereas the vertical axis is used
to represent the number of pixels in that particular pixel. Black and dark areas are represented in the left side of
the horizontal axis, medium grey color is represented in the middle, and the vertical axis represents the size of
the area.
• Histogram is the graphical representation of data, which is used for image enhancement
• It represents the frequency of occurrence of various gray levels.
• It is used for manipulating contrast and brightness.
• To get a high quality image, the histogram should be distributed over a place or in a flat profile.
In black image, the histogram values are placed towards 0 level
In black image, the histogram values are placed towards 0 level
i.e. left
i.e. left

In white image, the histogram values are placed towards 255


level i.e. right

For low contrast image, the histogram values are at the center
and not distributed

High quality image consists of histogram normalized in flat


surface; i.e. distributed among all level 0 to 255
Applications of Histograms

1. In digital image processing, histograms are used for simple calculations in software.
2. It is used to analyze an image. Properties of an image can be predicted by the detailed
study of the histogram.
3. The brightness of the image can be adjusted by having the details of its histogram.
4. The contrast of the image can be adjusted according to the need by having details of the x-
axis of a histogram.
5. It is used for image equalization. Gray level intensities are expanded along the x-axis to
produce a high contrast image.
6. Histograms are used in thresholding as it improves the appearance of the image.
7. If we have input and output histogram of an image, we can determine which type of
transformation is applied in the algorithm.
Histogram Processing Techniques
1. Histogram Sliding:
In Histogram sliding, the complete
histogram is shifted towards rightwards or
leftwards. When a histogram is shifted
towards the right or left, clear changes are
seen in the brightness of the image. The
brightness of the image is defined by the
intensity of light which is emitted by a
particular light source.
2. Histogram Stretching
• In histogram stretching, contrast of an image is increased. The contrast of an image is
defined between the maximum and minimum value of pixel intensity.
• If we want to increase the contrast of an image, histogram of that image will be fully
stretched and covered the dynamic range of the histogram.
• From histogram of an image, we can check that the image has low or high contrast.
3. Histogram Equalization
• Histogram equalization is used for equalizing all the pixel values of an image. Transformation
is done in such a way that uniform flattened histogram is produced.
• Histogram equalization increases the dynamic range of pixel values and makes an equal count
of pixels at each level which produces a flat histogram with high contrast image.
• While stretching histogram, the shape of histogram remains the same whereas in Histogram
equalization, the shape of histogram changes and it generates only one image.
Discuss the algorithm for histogram equalizations
Histogram equalization is one of the Pixel brightness transformations techniques. It is a well-known contrast
enhancement technique due to its performance on almost all types of image.
Example: Perform the histogram equalization of following pixel values

Histogram of input image.

Now needs to find the histogram


equalization for this input histogram.
PDF = Probability Distribution Function
CDF = Cumulative Distribution Function
As we can see that histogram of output
function is somewhat more distributed
than input image function.
The values are rescaled according to the input and output
limits, low_in and high_in,
and low_out and high_out respectively.
Lab 06: Histogram Equalization
Spatial Operations in DIP
Lab 07: Convolution Filtering
Lab 08: Median Filter
First Derivative Vs Second Derivative Filters
• Sensitivity to Noise: Second derivative filters are more sensitive to noise compared to first
derivative filters because they respond to changes in the rate of change, which can be affected by
small fluctuations in intensity.
• Edge Detection vs. Detail Enhancement: First derivative filters are primarily used for edge
detection due to their ability to highlight rapid changes in intensity. Second derivative filters,
meanwhile, can highlight finer details and are used for both edge detection and image enhancement.
• Response Pattern: First derivative filters produce a response that is directly proportional to the edge
slope, resulting in thicker edges for gradual intensity changes. Second derivative filters produce a
zero-crossing at the edge location, which can result in finer edge representations but may also detect
additional, non-edge features.
• For First Derivative: For Second Derivate, following properties
• Must be zero on flat segments apply:
• Must be non-zero at onset of a gray level or Must be zero in flat area
on ramp Must be non-zero at the onset and end of gray
• Must be non-zero along ramp level step or ramp
Must be zero along ramps of constant slope
Second figure is the one dimensional
horizontal line of the image. And last figure is
the simplified representation of second figure

In 1D: values are 0 on flat surfaces; non-zero


on slope or ramp. So thicker edges.
In Isolated point, the response of 2D(i.e. -12)
is much stronger than 1D (-6).

In 2D: values are 0 on flat surfaces; non-zero


on starting and ending point of ramp. So finer
edges. In Step, 1D & 2D remains same (i.e. 7)
Laplacian Filter in Image Processing

The Laplacian filter is a


second derivative filter
used in image processing
for edge detection. It
measures the rate at which
the first derivatives change,
allowing us to find regions
of rapid change (edges) in
images. The Laplacian
operator uses the second
spatial derivative of an
image to enhance regions
of rapid intensity change.
In table1: equal importance is given to
surroundings while less importance
given to center of image. Exact
opposite in table 3. In the last table,
only center will be highlighted while
others remain the same.
Edge Detection Filter
• Edges are usually one of the most important features in a structure, and can often be used for measurements
after appropriate edge detection has been applied.
• The edge detection filters available in Dragonfly can be used to emphasize the edges and transitions in an
image. Refer to the comparison chart below for a quick overview of the available filters. The edge detection
filter comparisons are as:
• Edge detection is a fundamental tool in image processing and computer vision, aimed at
identifying points in a digital image at which the image brightness changes sharply or, more
formally, has discontinuities. The points at which image brightness changes sharply are typically
organized into a set of curved line segments termed edges. The primary purpose of edge
detection is to significantly reduce the amount of data in an image, while preserving the
structural properties to be used for further image processing.
• Several algorithms and techniques can be used for edge detection, and they vary in terms of
complexity and the type of edges they can detect. The most common methods include:
1. Sobel Operator: Emphasizes edges in the vertical and horizontal direction by convolving the image with
a pair of 3x3 kernels. It is relatively simple but effective for many applications.
2. Canny Edge Detector: Aims to satisfy three main criteria: low error rate (detect as many real edges as
possible while minimizing the detection of false edges), good edge localization (detected edges are as
close as possible to the true edges), and minimal response (only a single edge detector response to a
single edge). It uses a multi-stage algorithm to detect a wide range of edges in images.
3. Prewitt Operator: Similar to the Sobel operator but uses a different kernel for detecting horizontal and
vertical edges. It is also simple and effective for basic edge detection tasks.
4. Laplacian of Gaussian (LoG): Involves smoothing the image with a Gaussian filter and then applying the
Laplacian operator to detect edges. This method is particularly good at detecting blob-like structures in
addition to edges.
Magnification in Image Processing

• Magnification in image processing is a technique used to increase the size of an image.


• It's a crucial part of many applications, from enhancing digital photographs to allowing
detailed analysis in scientific research.
• There are several methods to perform magnification, but two common ones are pixel
replication (also known as nearest neighbor interpolation) and interpolation (with methods
like bilinear, bicubic, and Lanczos).
• Each method has its own set of advantages and drawbacks.
1) Pixel Replication (Nearest Neighbor Interpolation)
Pixel replication is the simplest form of image magnification. It involves duplicating the pixels
in an image to enlarge it without introducing any new colors or gradients. Here's how it works:
1.Determine the Scale Factor: First, you decide how much larger you want the image to
be. For example, a scale factor of 2 means each pixel will be duplicated to create an image
twice the original size in each dimension.
2.Duplicate Pixels: For each pixel in the original image, create new pixels in the enlarged
image that have the same color value. If your scale factor is 2, each pixel in the original
image becomes a 2x2 block of pixels in the enlarged image with the same color.
• Advantages:
• Simplicity: It's straightforward to implement.
• Speed: It's faster than more complex interpolation methods because it doesn't involve any
calculations to create new pixel values.
• Drawbacks:
• Quality: The resulting image can appear blocky or pixelated, especially if the scale factor
is large. It doesn't handle diagonal lines or curves well.
Magnification using interpolation
Interpolation methods are more sophisticated and aim to create new pixel values that make the enlarged image
appear smoother and more continuous than what pixel replication can achieve. The main types include:
1. Bilinear Interpolation: This method considers the closest 2x2 neighborhood of known pixel values surrounding the
unknown pixel. It then performs a linear interpolation first in one direction and then in the other to generate the new
pixel value.
2. Bicubic Interpolation: Bicubic interpolation goes a step further by considering a 4x4 neighborhood of pixels for
interpolating. It uses cubic polynomials, leading to smoother images compared to bilinear interpolation.
3. Lanczos Interpolation: This method uses a sinc function to interpolate the new pixel values. It's often considered to
produce the highest quality results, especially for images with high contrast, but it's also the most computationally
intensive.
Advantages:
• Improved Quality: Interpolation generally produces smoother and more visually appealing images than pixel
replication, especially for higher magnification levels.
• Flexibility: Different interpolation methods offer a balance between computational complexity and image quality,
allowing for optimization based on the application's needs.
Drawbacks:
• Complexity: Interpolation methods are more complex to implement than pixel replication.
• Computational Cost: These methods are slower and more computationally intensive, especially for large images or
high magnification levels.
1. Explain "power law transformation" techniques for the purpose of image enhancement.
Explain the mean filter along with suitable algorithm for its implementation(4+6)

5. Discuss the algorithm for histogram equalization.

6. Explain the first derivative filter with a suitable example.

11. Discuss the magnification of image using interpolation technique.

3. What is an edge detection filter? Differentiate between the first derivative and second
derivative filter? Derive the filter mask for Laplacian filter and write the algorithm for its
implementation. [1+2+7=10]

4. Explain the term Contrast Stretching and the Histogram


Equalization.(3+1)
10. Derive the equation for Laplacian filter and write the
algorithm for its implementation.(6)

You might also like