DIP Module II
DIP Module II
Image Enhancement in the Spatial Domain: Some Basic Gray Level Transformations, Histogram
Processing, Enhancement Using Arithmetic/Logic Operations, Basics of Spatial Filtering,
Smoothing Spatial Filters, Sharpening Spatial Filters, Combining Spatial Enhancement Methods.
This technique is used to enhance white or light color detail in dark background, as dark
color in light background is easily visible than light color in dark background.
Log Transformation
The log transformation is of the form:
s = T(r) = c log (1 + r)
where, c is constant and r ≥ 0.
Log Transformation
In log transformation, the higher range of intensity level is mapped to a lesser range of
intensity level at the brighter side, whereas the lesser range of intensity level is mapped to
higher range of intensity level at the darker side.
The log transformation expands the dark pixels. Log transformation is applied when the
intensity levels are very large, for example, 0 to 10^6. This is because transformation
compresses the intensity levels of input level.
The inverse logarithmic transformation is called exponential transformation. It has the
opposite behaviour that of logarithmic transformation.
The higher range of intensity level is mapped to higher range of intensity level at the
brighter side, whereas the lesser range of intensity level is mapped to a lesser range of
intensity level at the darker side.
Power Law (Gamma) Transformation
The power law (or gamma) transformation is of the form:
s = T(r) = c * r ^ γ
where, c, γ are constants; c, γ > 0
For various values of γ, there exists a different power law transformation.
At γ < 1, the higher range of intensity level is mapped to a lower range of intensity level at
the brighter side, while the lower range of intensity level is mapped to higher range of
intensity level at the darker side.
At γ > 1, the behaviour is opposite that of γ < 1. Here, the higher range of intensity level is
mapped to a higher range of intensity level at the brighter side, while the lower range of
intensity level is mapped to lower range of intensity level at the darker side. If γ = 1, then
the transformation becomes identity transformation.
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.
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.
Histogram Processing Techniques
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.
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.
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.
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.
Consider for a moment continuous intensity values and let the variable r denote the intensities of
an image to be processed.
that produce an output intensity level s for every pixel in the input image having intensity r.
(a) Monotonically increasing function, showing how multiple values can map to
a single value.
(b) Strictly monotonically increasing function. This is a one-to-one mapping,
both ways.
The right side of this equation is recognized as the cumulative distribution function (CDF) of
random variable r.
Because PDFs always are positive and recalling that the integral of a function is the area under
the function. To find ps(s) the corresponding to the transformation:
Local Histogram Processing
The histogram processing methods are global, in the sense that pixels are modified by a
transformation function based on the intensity distribution of an entire image.
Although this global approach is suitable for overall enhancement, there are cases in which it is
necessary to enhance details over small areas in an image.
The number of pixels in these areas may have negligible influence on the computation of a
global transformation whose shape does not necessarily guarantee the desired local
enhancement.
The solution is to devise transformation functions based on the intensity distribution in a
neighborhood of every pixel in the image.
The histogram processing techniques previously described are easily adapted to local
enhancement.
The procedure is to define a neighborhood and move its center from pixel to pixel. At each
location, the histogram of the points in the neighborhood is computed and either a histogram
equalization or histogram specification transformation function is obtained.
This function is then used to map the intensity of the pixel centered in the neighborhood.
The addition of images is a simple process where corresponding pixel values of two images are
added together.
However, there are certain rules for handling the result. If the result is a floating-point number,
it needs to be rounded off.
If the result exceeds the pixel range (0 to 255 in an 8-bit grayscale image), the maximum range
value is selected.
If the result is below the pixel range, the minimum range value is chosen. Addition of images is
commonly used for noise reduction and image averaging.
Subtraction of Images
Subtraction of images involves subtracting corresponding pixel values from one another.
Similar to addition, the result needs to be handled Based on certain rules. If the result is below
zero, it is set to zero.
Subtraction is commonly used for image enhancement, detecting differences between images,
and in medical imaging for mask mode radiography.
Multiplication of Images
Multiplication of images is a process where corresponding pixel values are multiplied together.
Similar to addition and subtraction, the result needs to be managed. If the result exceeds the
pixel range, it is set to the maximum range value (255).
Multiplication is used for shading correction and masking or region of interest operations.
Division of Images
Division of images involves dividing corresponding pixel values. As with the other operations,
certain rules.
If the result is undefined or infinity, it is set to zero. Division is primarily used for shading
correction.
Applications of Arithmetic Operations
Multiplication is employed for shading correction and masking, and division is primarily used
for shading correction.
Logical Operations on Images
In addition to arithmetic operations, logical operations such as AND, OR, and NOT can also be
applied to images.
These operations are performed pixel by pixel and are commonly used in digital logic and
design.
The AND operation outputs a pixel value of 1 only when both inputs are 1, the OR operation
outputs a pixel value of 1 if any of the inputs are 1, and the NOT operation produces the
inverse of the input pixel value.
AND Operation
The AND operation is applied to corresponding pixel pairs of two images.
If both pixels are 1, the output is 1; otherwise, the output is 0. The AND operation is useful for
extracting common features from multiple images.
OR Operation
The OR operation is also performed on corresponding pixel pairs. If any of the two pixels are
1, the output is 1; otherwise, it is 0.
The OR operation is useful for combining images with different features or detecting specific
objects.
NOT Operation
The NOT operation is performed on a single image, inverting the pixel values. If the input
pixel is 0, the output will be 1, and vice versa.
The NOT operation can be employed for image manipulation and conversion.
The mechanics of linear spatial filtering using a 3*3 filter mask. The form chosen to denote the
coordinates of the filter mask coefficients simplifies writing expressions for linear filtering.
The mechanics of linear spatial filtering using a 3*3 neighborhood. At any point (x, y) in the
image, the response, g (x, y) , of the filter is the sum of products of the filter coefficients and the
image pixels encompassed by the filter:
Spatial Correlation and Convolution
There are two closely related concepts that must be understood clearly when performing linear
spatial filtering. One is correlation and the other is convolution.
Correlation is the process of moving a filter mask over the image and computing the sum of
products at each location.
The mechanics of convolution are the same, except that the filter is first rotated by 180°.
Spatial correlation refers to the relationship between pixel values at different spatial locations in
an image. It essentially measures how the intensity values of one part of the image are related to
the intensity values of another part. In image processing, this is often used to detect patterns,
similarities, or redundancies in an image.
Mathematically, the spatial correlation is expressed as the product of the pixel values in one
region and a filter or mask (often called a kernel) applied to another region.
This operation is performed across the entire image, typically to find features like textures or
edges.
The filter "slides" over the image, and the result is a new image showing the correlated areas.
Convolution
Convolution is a more specific operation that is closely related to correlation. In convolution, an
image is processed with a kernel or filter to extract certain features, such as edges, blurs, or
sharpened details. The key difference between convolution and correlation is that in convolution,
the kernel is flipped both horizontally and vertically before being applied to the image.
The process of convolution involves the following steps:
1. The kernel (or filter) slides over the image.
2. At each position, the pixel values in the image are multiplied by the corresponding values in
the kernel.
3. The results of the multiplications are summed up to produce a single output pixel.
4. This process is repeated for all pixels in the image.
Convolution is widely used for operations like edge detection, blurring and sharpening .
where the s are the coefficients of an m*n filter and the zs are the corresponding image
intensities encompassed by the filter
Smoothing filters are used for blurring and for 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 curves.
Noise reduction can be accomplished by blurring with a linear filter and also by nonlinear
filtering.
The output (response) of a smoothing, linear spatial filter is simply the average of the pixels
contained in the neighborhood of the filter mask.
These filters sometimes are called averaging filters. The idea behind smoothing filters is
straightforward.
By replacing the value of every pixel in an image by the average of the intensity levels in the
neighborhood defined by the filter mask, this process results in an image with reduced “sharp”
transitions in intensities.
Because random noise typically consists of sharp transitions in intensity levels, the most
obvious application of smoothing is noise reduction.
However, edges (which almost always are desirable features of an image) also are
characterized by sharp intensity transitions, so averaging filters have the undesirable side effect
that they blur edges.
Another application of this type of process includes the smoothing of false contours that result
from using an insufficient number of intensity levels.
Two 3*3 smoothing (averaging) filter masks
The idea here is that it is computationally more efficient to have coefficients valued 1. At the
end of the filtering process the entire image is divided by 9.
An m*n mask would have a normalizing constant equal to1/ mn.
A spatial averaging filter in which all coefficients are equal sometimes is called a box filter. The
second mask is a little more interesting.
This mask yields a so called weighted average, terminology used to indicate that pixels are
multiplied by different coefficients, thus giving more importance (weight) to some pixels at the
expense of others.
Because we are dealing with digital quantities whose values are finite, the maximum possible
intensity change also is finite, and the shortest distance over which that change can occur is
between adjacent pixels.
A basic definition of the first-order derivative of a one-dimensional function f(x) is the difference
When computing the first derivative at a location x, we subtract the value of the function at that
location from the next point. So this is a “look-ahead” operation.
Edges in digital images often are ramp-like transitions in intensity, in which case the first
derivative of the image would result in thick edges because the derivative is nonzero along a
ramp. On the other hand, the second derivative would produce a double edge one pixel thick,
separated by zeros.
From this, that the second derivative enhances fine detail much better than the first derivative, a
property that is ideally suited for sharpening images.
Using the Second Derivative for Image Sharpening—The Laplacian
Isotropic filters are rotation invariant, in the sense that rotating the image and then applying the
filter gives the same result as applying the filter to the image first and then rotating the result.
It follows from the preceding three equations that the discrete Laplacian of two variables is
This equation can be implemented using the filter mask in which gives an isotropic result for
rotations in increments of 90°.
Because the Laplacian is a derivative operator, its use highlights intensity discontinuities in an
image and deemphasizes regions with slowly varying intensity levels.
This will tend to produce images that have grayish edge lines and other discontinuities, all
superimposed on a dark, featureless background.
(a) Filter mask used to implement(b) Mask used to implement an extension of this equation that
includes the diagonal terms. (c) and (d) Two other implementations of the Laplacian found
frequently in practice.
Unsharp Masking and High boost Filtering
A process that has been used for many years by the printing and publishing industry to sharpen
images consists of subtracting an unsharp (smoothed) version of an image from the original
image. This process, called unsharp masking, consists of the following steps:
1. Blur the original image.
2. Subtract the blurred image from the original (the resulting difference is called the mask.
3. Add the mask to the original.
Letting f (x, y) denote the blurred image, unsharp masking is expressed in equation form as
follows. First we obtain the mask:
Then we add a weighted portion of the mask back to the original image:
1-D illustration of the mechanics of unsharp masking. (a) Original signal. (b) Blurred
signal with original shown dashed for reference. (c) Unsharp mask. (d) Sharpened
signal, obtained by adding (c) to (a).
The points at which a change of slope in the intensity occurs in the signal are now emphasized
(sharpened).
Observe that negative values were added to the original.
Thus, it is possible for the final result to have negative intensities if the original image has any
zero values or if the value of k is chosen large enough to emphasize the peaks of the mask to a
level larger than the minimum value in the original.
Negative values would cause a dark halo around edges, which, if k is large enough, can produce
objectionable results.
Because the components of the gradient vector are derivatives, they are linear operators.
However, the magnitude of this vector is not because of the squaring and square root operations.
The computations of gx and gy are linear operation because they involve derivatives and,
therefore, can be implemented as a sum of products using the spatial masks.
The nonlinear aspect of sharpening with the gradient is the computation of M(x, y) involving
squaring and square roots, or the use of absolute values, all of which are nonlinear operations.
These operations are performed after the linear process that yields gx and gy.
Examples of combinations:
Smoothing followed by sharpening: Blurring an image slightly with a low-pass filter can
reduce noise before applying a sharpening filter to enhance edges.
Edge detection with contrast enhancement: Applying an edge detection filter to identify
edges, then boosting the contrast in those edge areas to make them more prominent.
Histogram equalization with local enhancement: Adjusting the overall image intensity
distribution using histogram equalization, then applying a local enhancement technique to
specific areas of interest.
Combine spatial enhancement methods:
Direct addition:
Simply add the outputs of different filters together after applying them to the image.
Weighted addition:
Assign different weights to the outputs of different filters depending on their importance for the
desired enhancement outcome.
Masking:
Create a mask that defines the regions where specific filters should be applied more strongly.
Important considerations:
Filter selection:
Choosing appropriate filters based on the image characteristics and desired enhancement goals is
crucial.
Parameter tuning:
Adjusting filter parameters (like kernel size, sigma value) can significantly impact the results.
Evaluation:
Assessing the quality of the enhanced image subjectively (visual inspection) or objectively
(using image quality metrics) is important to determine if the combination of filters is effective.