Professional Documents
Culture Documents
Engineering
2. Image Arithmetic
3. Affine Transformation
4. Point Operations
5. Neighbourhood Operations
6. Image histogram
Experiment-1
Distance and Connectivity
Objective
The objective of this experiment is to understand the notion of connectivity and
neighbourhood defined for a point in an image. These concepts are useful in
finding if two points are neighbours in some sense and quantify the distance
between them.
Introduction
In most image processing tasks, basic operations typically involve modification
of a pixel’s value based on the value of its neighbours. A digital image is
defined on a discrete grid of points. Hence there are different ways in which
one can define the spatial relation between pixels. For instance, we could
consider two pixels as ‘neighbours’ only if they share one side/ edge.
Alternately, two pixels could be neighbours if they share a vertex. These two
leads to different definitions of neighbourhood for a pixel. The extent of a
neighbourhood is also of interest as it is useful in finding not only which pixels
belong to an object in an image but also the extent of the object.
The notions of connectivity and distance between two pixels are useful in
defining the neighbourhood for a pixel. Connectivity tells us which pixels are
`next’ to which. It helps answer questions like “Can we reach pixel p0 from
pixel p1?” The concept of connectivity also helps simplify the definition of
region or boundary in an image. Once we know we can reach p1 from p0, the
cost to reach or distance is of interest. There are different distance metrics and
we will study them in this experiment.
Theory
Connectivity of pixels:
Pixel connectivity describes a relation between two or more pixels. For two
pixels to be connected they must fulfill certain conditions on the pixel value
and spatial adjacency.
4 - neighbours
8 - neighbours
q is in N4(p), or
Their pixel values must be from the same set of values C. For a grayscale
image, C might be any range of possible Gray-level values 0 to 255, e.g. C= {12,
13, …. 40}, for a binary image we simply have
C = {1}.
Properties of connectivity:
In the event there is only one connected component, the set S is said to be a
connected set and S is called a region in the given image.
The boundary of a region R is the set of pixels in the region that have at least
one neighbour that is not in R.
Distance Metrics:
On a discrete grid, the distance between two points a: (xa, ya) and b: (xb, yb)
can be defined in a variety of ways.
Euclidean distance:
In vector form, this is referred to as L2 norm.
Chess-board distance: This is the 8-connected distance D8, also called as chess-
board distance.
Using these distance metrics, for a given pixel p, one can find pixels at equal
distance from this pixel. These pixels form the iso-distance pixel set for the
point p.
Let a, b and c be three pixels with coordinates (xa, ya), (xa, yb) and (xc, yc)
respectively. A distance function D is a metric if it has the following properties:
D(a, b) = D(a, b)
Procedure
The experiment is designed to understand the concept of distance and
connectivity in digital images. This experiment consists of three
experiments:
Steps to run
Experiment-1:
Select two points on the image grid by doing mouse click on red and
green squares which highlight your select location.
Select “run” option to see the distance between two selected points w.r.t
to the given distance metrics
Experiment-2:
Select distance value using distance scroll bar appeared next to it.
Select “run” option to see iso-distance points w.r.t to the input point
Experiment-3:
Left image panel shows a binary image and small red point on it.
To study the effect of these operations on the dynamic range of the output image.
To study methods to enforce closure - force the output image to also be an 8 bit
image.
Introduction
In image arithmetic, we consider operations such as I(x,y) = A (x,y) o B(x,y) where
o is an arithmetic operation such as addition, subtraction, multiplication or division.
Here, A and B could be derived from different sources. Such operations are
particularly used in modelling image acquisition as a result of a perfect image
corrupted with (additive or multiplicative) noise. The noise is often introduced either
by a transmission medium or the camera.
Theory
A (x,y) o B(x,y) = I(x,y)
The important requirement in image arithmetic is that all (input and output) the
images are of the same size MxM.
Arithmetic operations are done pixelwise. Let p = A(x,y) and q = B(x,y) be the pixel
values to be operated on and r =I(x,y) be the result of the operation.
Addition
Subtraction
Multiplication:
Division:
Implementation issues:
Digital images are stored as b - bit images. Hence, the range of values a pixel can
take is restricted to the range [ 0, 1,... (2b -1)]. With b= 8 this range is [0,1,...255].
The closed interval poses a problem when performing arithmetic operations in
practice, as the results are not guaranteed to be within this interval. For an 8-bit
image the intervals for the output pixel for each operation are:
Division: r ∈ [0,∞]
Clipping- Map all negative pixel values ( r < 0) to zero and all values above 255 to
255.
Auto scaling - This operation remaps the range of r to fit to be in [0, 255] as follows.
Let ra be the autoscaled value.
ra = 255 x (r - rmin)/(rmax-rmin)
Where, rmax and rmin are the maximum and minimum values of an arithmetic
operation.
Procedure
The experiment is design to understand and learn the image arithmetic concepts.
This experiment consists five parts:
Image addition
Image Subtraction
Image Difference
Image Multiplication
Image Division
Select secondary image by choosing either of the 'dull' , 'bright' or 'gradient' images
Interesting Observations
Do the Multiplication operation first with clipping and then with auto-scaling, and
compare the results.
Experiment-3
Affine Transformation
Objectives
To learn basic image transformation
Translation
Rotation
Scaling
To learn the role of interpolation operation
Bi-linear
Bi-cubic
Nearest neighbor
To learn the effect of multiple transformations
Significance of order in which one carried out
Introduction
In cricket, to decide if a batsman has been run out, the standard practice is to select
the part of the image around the stumps and zoom on it so that the third umpire can
take a decision. The region of interest is the crease. If one were to automate this
process, several steps are required. This will include identifying the stump region
and rotating the image so that the crease is at the right orientation and scale to
enable an accurate judgement.
The set of transformations that will possibly be required are translation (to place the
crease within the view window), rotation (to orient the crease such that the bat is
seen to the left or right of it) and finally scaling so the bat position relative to the
crease can be determined accurately.
The set of transformations namely, translation, rotation, scale and shear (stretching
in one direction) forms the affine class of transformations. In this experiment, we
will study how the first three types of transformations are effected on a given image.
Theory
An affine transformation is a geometrical transformation which moves points in
space such that points which were lying on a line remain so after the transformation.
Given a point which is a point location [x, y]T , transformed location after
translation, rotation and scaling can be as follows.
Translation
Rotation (θ)
Scaling
Find the locations [m, n] in I that correspond to locations [., n.] in the image X by
applying the inverse transformation. I.e. A-1 ([m., n.]-B) = [m, n]. This can result in
non-integer locations.
Find the pixel value at these source locations. If it is non-integer valued locations,
use an interpolation function.
Example: Consider A to be rotation by 30 degrees. Let us take the location [12, 13]
in X and find its corresponding location in I. This will be [3.89 17.26]. To determine
the value of I at this location, we can use the known values closest to this location
Option 1: Round off the [m, n] and take the pixel value at that location. This is
known as the nearest neighbour interpolation method.
Option 2: Take the weighted average of the 4 neighbouring pixels. The weights are
the distance between the desired location and that of the neighbours. The common
form is the bilinear form which is a second order approximation and equivalent to
fitting a straight line pairs of neighbouring pixels.
Procedure
Single Transformation
Select one choice among three choices: scaling, rotation and translation
For rotation and scaling, select interpolation function to see the difference in the
output. The default choice for interpolation function is nearest neighbor.
Select .run. option to see the output under the selected parameters
To view the full sized output image, select .view full size image.
Panel below input and output image panel shows the intermediate results obtained
during operation. Click on the thumbnails to view images in full size.
Multiple Transformations
Order selection panel will be pop out. Select the order in which you want to perform
the operation. The order sequence is displayed in front of each transformation
choice. During operation, edit option is provided below in the left panel to change
the selected order of operation.
The interpolation function is kept fixed i.e. nearest neighbor for this operation
In case you do not want any particular transformation. Do not change parameter of
the respective choice
Output panel and intermediate results panel will display the obtained output.
Experiment-4
Point Operations
Objective
To learn image enhancement through point transformation
Linear transformation
Non-linear transformation
Introduction
The most popular application of image processing is to change the visual appearance
of the image such as to improve the contrast, reduce the dynamic range of
brightness, reverse the 'polarity' such as dark to white and vice versa. There are
many image editing tools which enable one to do such alteration in the appearance
of the image. Besides such everyday uses, these operations play an important role
in many domains such as medical imaging, remote sensing, to overcome the
inherent limitations in imaging acquisition process, adapting the image to different
displays and so on.
q = T(p)
There are four commonly used and basic types of functions (transformation) are
described here:
Linear function
Non-linear function
Clipping
Window function
Linear function: The output pixel value is linearly related to the input pixel value.
This can be described using a line equation as follows:
q= s * p + o;
where, s is the slope of the line and o is the offset from the origin. This type of
transformation is particularly useful for enhancing white of gray details embedded in
the dark regions of an image.
Non-linear function: The output pixel value is not linearly related to the input pixel
value. Here, we consider example of log-transformation function to explain the
process. In this function is:
q= c * log(1+p)
where c is a constant variable. This function converts a narrow range of low gray-
level values of p in to a wider range of q values or vice versa. This type of
transformation is useful in expanding values of dark pixels while compressing the
higher values.
Clipping: The value of output pixel is related to the input pixel value in piece-wise
linear fashion. Though such functions are complex and require user input but useful
in many practical situations. This function is defined as
where, a and b are constant variables which define input pixel value range in which
linear function with a slope s and offset o is applied. In gray level image, value of L
is 255. In our experiment section, we kept value of offset fixed to zero.
Window: This function is similar to the clipper. In this, only a desired range of gray
levels is preserved in the output image. It is defined as:
Procedure
The experiments are designed to understand and learn the effect of different gray-
level transformation functions. This experiment consists of four experimentations:
Linear
Non-linear
Clipping
Windowing
With the change in the parameters, the corresponding transformation function will
be display in the left below panel
Neighbourhood Operations
Objective
To learn about neighbourhood operations and use them for
Linear filtering
Non-linear filtering
Introduction
Neighbourhood operations are a generalization of the point operations. A pixel in the
processed image now depends not only on the corresponding pixel in the input
image but also its neighbouring pixels. This generalization also allows for defining
linear as well nonlinear filtering operations. An example of linear filtering in image
editing is to produce a soft focus effect by smoothing away the fine details. Image
denoising is another application where neighbourhood operations are very useful.
During transmission, an image may get corrupted with salt and pepper noise, where
isolated pixels turn black or white and stand out from their background. Performing
a nonlinear filtering such as replacing a pixel by the median value of its
neighbourhood values effectively removes the noise.
In this experiment, you will study the linear and non-linear operations. Specifically,
you will study the effect of changing the size of the neighbourhood and the rule for
combining the pixel values from the neighbourhood, on the result of processing.
Theory
Given an input image f(x,y) an output image g(x,y) is computed by applying some
operation on a local neighbourhood N of each pixel in the image f. This can be
visualized as follows: a window or mask is placed at every pixel location in f(x,y)
and some operation is performed on the pixels within the window. The window is
moved to the next pixel location nd the process is repeated. Thus,
Linear operations :
Triangular filter:All the coefficients are arranged to form a pyramid (with triangular
faces) as shown below
Gaussian filter: The filter coefficients form a bell shaped surface as shown below.
Nonlinear Operations:
Median filter: The operator HN computes the median of the set of grey values in the
neighborhood of the current pixel in f(x,y). This is found by performing a sorting
operation at every location (x,y) in f(x,y).
Unsharp Masking filter: This is another example of nonlinear filtering. Here, the aim
is to highlight the details. This operation is given by
Implementation Issues
When a pixel lies in the border of the input image, some elements of its
neighbourhood is not defined. Hence the mask cannot be applied. To circumvent this
issue, one of the following two approaches can be used :
Zero Padding : The undefined pixels are assumed to be zero and the mask can be
applied. For example: An input image of size MXN and filter size mXn, the output
image size will be (M+(m-1)/2) X (N+(n-1)/2)
Repetition : The border pixels in input image are repeated, so that the
neighbourhood is always defined and mask can be applied.
Procedure
The experiment is designed to understand and learn the Neighborhood operations in
images. This experiment consists of two experiments
Linear filtering
Non-linear filtering
Straight average
Triangular average
Gaussian average
Median filter
Unsharp filter
Interesting Observations
Try any filtering option with different neighborhood sizes and compare the results
Try straight average and Gaussian average on same image and same neighborhood
size and compare the results.
Experiment-6
Image Histogram
Objectives
To understand how frequency distribution can be used to represent an image.
To study the correlation between the visual quality of an image with its histogram.
Introduction
A histogram of an image represents the distribution of pixel intensities in the image.
Histograms provide statistical information about the image. These are of use in
applications such as image enhancement, compression and segmentation. For
instance, based on the information present in histogram, it is possible to develop a
transformation function which improves the quality or visual appearance of an
image.
Theory
Given an image A, its histogram H(k) is derived by counting the number of pixels at
every grey level k.
H(k) = Nk k = 0,1,2.....K-1.
where Nk is the count of pixels at gray level k. The total number of bins in this
histogram is K . Theoretically, the maximum value for K is determined by the pixel
depth M of the image. For instance, for an M=8-bit greyscale image, we can have up
to 2M = 256 = K bins and for a binary image (1-bit) we can have just 2 bins.
Sometimes, the value of K is chosen to be different from2M. This will alter the
appearance of the histogram. The example below illustrates this effect.
The histogram of an image is a good indicator of the contrast and brightness of a
given image.
These information in turn are useful for processing a given image to enhance or
analyse the content of the image which is described in detail next.
Histogram Processing:
Histogram equalization can be done at a global or local level. In the global level the
histogram of the entire image is processed whereas at the local level, the given
image is subdivided and the histograms of the subdivisions (or subimages) are
manipulated individually. When histogram equalization is applied locally, the
procedure is called Adaptive Histogram Equalization.
Procedure
The experiment is designed to understand and learn the image histogram concepts.
(A) Histogram:
2. Select one option from 'Full Image Histogram' and 'Divided Histogram'
(B) Processing:
End