You are on page 1of 14

# Image Pre-Processing

STATISTICAL
ANALYSIS........................................................................................................................................................
... 2
HISTOGRAM OPERATIONS -
STRETCHING....................................................................................................................... 2
HISTOGRAM OPERATIONS -
MAPPING............................................................................................................................. 3
NOISES..............................................................................................................................................................
............................... 3
FILTERS...........................................................................................................................................................
................................ 3
EDGE
DETECTORS:..................................................................................................................................................
.................... 4
............................... 4
Roberts:.....................................................................................................................................................
............................. 4
Sobel.........................................................................................................................................................
.............................. 4
Prewitt.......................................................................................................................................................
............................. 5
Laplacian..................................................................................................................................................
............................. 6
Canny........................................................................................................................................................
.............................. 8
IMAGE PREPROCESSING ALGORITHM
PHASES:........................................................................................................... 10
EXAMPLES OF RAFAEL
IMAGES:......................................................................................................................................... 11
BULLET:.......................................................................................................................................................
.............................. 11
PARTICLES:.................................................................................................................................................
............................. 12
DROPS:.........................................................................................................................................................
.............................. 13
There are 3 basic operation that are used as pre-processing:
Statistical analysis
Histogram operations - stretching

If we take an image and count up how many pixels go into each gray level,
putting each one in a separate bin, we have a histogram. In mathematical
terms, the histogram is given by applying the relation
to it, where s is the level for every pixel value r in the original image, T( ) is
the transform function, n sub j is the number of times this level appears in
the image, and n is the total number of pixels in the image. If we plot each of
these bins, we have the graph of the histogram of beach.tiff. Another way to
get the histogram is to use the C code, as following:

char image[rows][cols];
int histogram[256];
int row, col, i;

## for (i = 0; i < 256; i++)

histogram[j]=0;
for (row = 0; row < rows; row++)
for(col = 0; col < cols; col++)
histogram[(int) image[row][col]++;

Really simple, isn't it? As you can see by the following plot, the picture is
low contrast, as well as being a very dark image.
Now, since this plot gives an estimate of the probability of occurrence of a
certain gray level, we can stretch out the probability and remap the values
for all the pixels in the image to these new values. Essentially, what we are
doing is taking the bins and stretching them out over the entire value range.
Doing this, we get the following graph of the histogram of beach_str.tiff.
Histogram operations - mapping
The histogram of pixel intensities in an image of a natural scene that has
been linearly quantized is usually highly skewed toward darker levels. Detail
is often imperceptible in the darker regions when such an image is viewed
on a conventional display with only 8-bit pixels. Histogram modification can
alleviate this problem by rescaling the original image so that the histogram
of pixel intensities follows some preferred form.
Histogram equalization flattens the output histogram, and may often be
appropriate for astronomical images. Exponential and hyperbolic output
histograms are also sometimes used, so that a final histogram "equalization"
is performed (approximately) by the quasi-logarithmic response of the user's
retina

Noises
1) Salt & paper
2) Gaussian
3) Place dependant intensity shift
4) Speckles
Filters
5) Median
6) Edge-preserving smooth
7) Erode
8) Dilate
9) Intensity normalization

Edge detectors:

Roberts:

## The Roberts cross operator provides a simple approximation to the

wh
ere Gx and Gy are calculated using the following masks:
As with the previous 2 x 2 gradient operator, the differences are
computed at the interpolated point [i + 1/2, j + 1/2]. The Roberts
operator is an approximation to the continuous gradient at this
interpolated point and not at the point [i, j] as might be expected.

Sobel

## A way to avoid having the gradient calculated about an interpolated

point between pixels is to use a 3 x 3 neighborhood for the gradient
calculations. Consider the arrangement of pixels about the pixel [i, j]
shown in the Figure 5.2.2.1 The Sobel operator is the magnitude of
where the partial derivatives are computed by:
with the constant c = 2.

## Like the other gradient operators, Sx and Sy can be implemented

Note that this operator places an emphasis on pixels that are closer
to the center of the mask. The Sobel operator is one of the most
commonly used edge detectors.
Figure 5.2.2.1: The labeling of neighborhood pixels used to explain
the Sobel and Prewitt operators

Prewitt
The Prewitt operator uses the same equations as the Sobel operator,
except that the constant c = 1. Therefore:

Note that, unlike the Sobel operator, this operator does not place any
emphasis on pixels that are closer to the center of the masks.

Laplacian
The edge points of an image can be detected by finding the zero
crossings of the second derivative of the image intensity. The idea is
illustrated for a 1D signal in Figure 5.3.1. However, calculating
2nd derivative is very sensitive to noise. This noise should be filtered
out before edge detection. To achieve this, “Laplacian of Gaussian” is
used. This method combines Gaussian filtering with the Laplacian for
edge detection.
Figure 5.3.1 1st and 2nd derivative of an edge illustrated in one dimension.
The first graph represents an edge in 1D.
In Laplacian of Gaussian edge detection there are mainly three steps:
· Filtering,
· Enhancement,
· and detection.
Gaussian filter is used for smoothing and the second derivative of
which is used for the enhancement step. The detection criterion is the
presence of a zero crossing in the second derivative with the
corresponding large peak in the first derivative.
In this approach, firstly noise is reduced by convoluting the image
with a Gaussian filter. Isolated noise points and small structures are
filtered out. With smoothing; however; edges are spread. Those
pixels, that have locally maximum gradient, are considered as edges
by the edge detector in which zero crossings of the second derivative
are used. To avoid detection of insignificant edges, only the zero
crossings whose corresponding first derivative is above some
threshold, are selected as edge point. The edge direction is obtained
using the direction in which zero crossing occurs.
The output of the Laplacian of Gaussian (LoG) operator; h(x,y); is
obtained by the convolution operation:

where

## is co mmonly called the mexican hat operator.

In the LoG there are two methods which are mathematically
equivalent:
· Convolve the image with a gaussian smoothing filter and compute
the Laplacian of the result,
· Convolve the image with the linear filter that is the Laplacian of the
Gaussian filter.
This is also the case in the LoG. Smoothing (filtering) is performed
with a Gaussian filter, enhancement is done by transforming edges
into zero crossings and detection is done by detecting the zero
crossings.

Canny
The Canny Edge Detection Algorithm has the following steps:
· Smooth the image with a Gaussian filter,
· Compute the gradient magnitude and orientation using finite-
difference approximations for the partial derivatives,
· Apply nonmaxima suppression to the gradient magnitude,
· Use the double thresholding algorithm to detect and link edges.
Canny edge detector approximates the operator that optimizes the
product of signal-to-noise ratio and localization. It is generally the first
derivative of a Gaussian.
Smoothing:
Let denote th e image; be a Gaussian smoothing filter
where is the spread of the Gaussian and controls the degree of
smoothing. The result of convolution of with gives an
array of smoothed data as:

Firstly, the gradient of the smoothed array is used to produce
the x and y partial derivatives and respectively as:

The x and y partial derivatives are computed with averaging the finite
differences over the 2x2 square. From the standard formulas for
rectangular-to-polar conversion, the magnitude and orientation of the
Here the arctan(x,y) function takes two arguments and generates an
angle.

Nonmaxima Suppression:
Given the being the magnitude image array one can apply the
thresholding operation in the gradient-based method and end up with
ridges of edge pixel. But canny has a more sophisticated approach to
the problem. In this approach an edge point is defined to be a point
whose strength is locally maximum in the direction of the gradient.
This is a stronger constraint to satisfy and is used to thin the ridges
found by thresholding. This process, which results in one pixel wide
ridges, is called “Nonmaxima Suppression”.
After nonmaxima suppression one ends up with an image which is
zero everywhere except the local maxima points. At the local maxima
points the value of is preserved.
Thresholding:
In spite of the smoothing performed as the first step in edge
detection, the nonmaxima suppressed magnitude imagewill contain
many false edge fragments caused by noise and fine texture. The
contrast of the false edge fragments is small.
These false edge fragments in the nonmaxima-suppressed gradient
magnitude should be reduced. One typical procedure is to apply a
threshold to . All values below the threshold are set to zero. After the
application of threshold to the nonmaxima-suppressed magnitude, an
array E(i,j) containing the edges detected in the image is obtained.
However; in this method applying the proper threshold value is
difficult and involves trial and error. Because of this difficulty, in the
array E(i,j) there may still be some false edges if the threshold is too
low or some edges may be missing if the threshold is too high. A
more effective thresholding scheme uses two thresholds.
To overcome the problem, two threshold values, and are applied
to . Here . With these threshold values, two thresholded
edge images and are produced. The image has gaps
in the contours but contains fewer false edges. With the double
thresholding algorithm the edges in are linked into contours. When
it reaches the end of a contour, algorithm looks in at the locations
of the 8-neighbours for edges that can be linked to the contour. This
algorithm continues until the gap has been bridged to an edge in .
The algorithm performs edge linking as a by-product of thresholding
and resolves some of the problems with choosing a threshold.

## 1. In case of salt & paper noise, if exist apply the proper

median-filter.
2. In case of for Gausian noise, if exist apply the Edge-
preserving smooth (mean filter).
3. In case of for speckles, if exists apply a combination of Erode
Delate and Median filters.
4. Assuming that the level of noise in the image is significantly
reduced, test if the input image intensity histogram bounded
above and below within a partial range of the complete 255 gray
level space. If so apply histogram stretching on 10% threshold
from the maximum peak, on the initial gray-level range (light -
weighted stretching) - see example.
5. Test if the result image has more contours pixels then the
previous one. If so it's considered "better". Go to step 1 until the
result image is not better then the original one.
6. According to the nature of the image apply the proper edge
detector.

## Examples of Rafael Images:

Bullet:

(1) Is the original image, (2) is the same image after edge-preserving smoothing filter, (3) is the previous