Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 74

Chapter-3

Point

Operati
Arithmetic
on on
Geometric
DIP

3/20/16

Prepared By: Haftu H.

3.1 Point operations


Is

an operation in which each pixel


at the output image is function of
the gray level of the pixel at the
corresponding position in the input
image, and only of that pixel.
They cant alter the spatial
relationship of the image.
Typical application of point
operations.
Photometric decalibration, to remove
the effects of spatial variations in the
camera system; 3/20/16 Prepared By: Haftu H.

3.1.1Logarithmic transform
The

dynamic range of an image can


be compressed by replacing each
pixel value in a given image with its
logarithm: Ioutput(i,j) = lnIinput(i,j),
where I(i,j) is the value of a pixel at a
location (i,j) in image I and the
function ln() represents the natural
logarithm.
In practice, as the logarithm is
undefined for zero, the following
general form of the logarithmic
transform is used:
3/20/16

Prepared By: Haftu H.

Contd
Note

that the scaling factor controls


the input range to the logarithmic
function, whilst c scales the output over
the image quantization range 0 to 255.
The addition of 1 is included to prevent
problems where the logarithm is
undefined for Iinput(i,j) =0.
The effect of the logarithmic transform
is to increase the dynamic range of
dark regions in an image and decrease
the dynamic range in the light regions.
3/20/16

Prepared By: Haftu H.

Contd
Thus,

the logarithmic transform maps


the lower intensity values or dark
regions into a larger number of grey
scale values and compresses the higher
intensity values or light regions in to a
smaller range of grey scale values.

s = log(1 + r)

3/20/16

Prepared By: Haftu H.

Matlab code
We

can see that increasing the


multiplication constant c increases
the overall brightness of the image.

3/20/16

Prepared By: Haftu H.

3.1.2 Exponential transform

The

exponential transform is the


inverse of the logarithmic transform.
Here, the mapping function is defined
by the given base e raised to the
power of the input pixel value:

This

transform enhances detail in highvalue regions of the image (bright)


whilst decreasing the dynamic range in
low-value regions (dark) the opposite
effect to the logarithmic transform.
3/20/16

Prepared By: Haftu H.

Contd
Here, we see that the contrast of the
background in the original image can be
improved by applying the exponential
transform, but at the expense of contrast
in the darker areas of the image.
The background is a high-valued area of
the image (bright), whilst the darker
regions have low pixel values.
This effect increases as the base number
is increased.

3/20/16

Prepared By: Haftu H.

Matlab code

3/20/16

Prepared By: Haftu H.

3.1.3 Power law transform


An

alternative to both the logarithmic and


exponential transforms is the raise to a
power or power-law transform in which each
input pixel value is raised to a fixed power:

general, a value of > 1 enhances the


contrast of high-value portions of the image
at the expense of low-value regions, whilst
we see the reverse for < 1.
This gives the power-law transform
properties similar to both the logarithmic <
1 and exponential > 1 transforms. The
constant c performs range scaling as before.
In

3/20/16

Prepared By: Haftu H.

10

Matlab code

3/20/16

Prepared By: Haftu H.

11

Please check the effect of y?

3/20/16

Prepared By: Haftu H.

12

Application: Gamma Correction.


Gamma

correction is the term used


to describe the correction required
for the nonlinear output curve of
modern computer displays.
When we display a given intensity
on a monitor we vary the analogue
voltage in proportion to the
intensity required.
The problem that all monitors share
is the nonlinear relationship
between input voltage and output
intensity.
3/20/16

Prepared By: Haftu H.

13

Contd
The

problem that all monitors share is the nonlinear


relationship between input voltage and output intensity. In
fact, the monitor output intensity generally varies with the
power of input voltage curve, as
approximately =2.5 (this varies with type of monitor,
manufacturer, age, etc.).
This means that, when you request an output intensity equal
to say i, you in fact get an intensity of i 2.5.
In order to counter this problem, we can preprocess image
intensities using an inverse power-law transform prior to
output to ensure they are displayed correctly.
Thus, if the effect of the display gamma can be characterized
as
Ioutput(i,j) = Iinput(i,j)
where is the r value for the output curve of the monitor (lower
right), then pre-correcting the input with the inverse
power-law transform, i.e. Iinput(i,j)1/, compensates to produce the
correct output as
Ioutput(i,j) = Iinput(i,j)1/. = Iinput(i,j)
3/20/16

Prepared By: Haftu H.

14

Matlab code
Please

have a look on
>> doc imadjust!!!

3/20/16

Prepared By: Haftu H.

15

3.2 Arithmetic Operations


Introduction:

The most basic type of image-processing


operation is a point transform which maps
the values at individual points (i.e. pixels) in
the input image to corresponding points
(pixels) in an output image.
In the mathematical sense, this is a one-toone functional mapping from input to output.
The simplest examples of such image
transformations are arithmetic or logical
operations on images.
Each is performed as an operation between
two images IA and IB or between an image
and a constant value C:
3/20/16

Prepared By: Haftu H.

16

Contd

Ioutput = IA + IB
Ioutput = IA + C
In both cases, the values at an individual
pixel location (i,j) in the output image are
mapped as follows:
Ioutput(i,j)= IA(i,j) + IB(i,j)
Ioutput(i,j)= IA(i,j) + C
To perform the operation over an entire
image of dimension C,R, we simply iterate
over all image indices for (I,j) = {0 . . . C1; 0 . . . R-1} in the general case (N.B. in
Matlab pixel indices are {1 . . C;1 . . R}).
3/20/16

Prepared By: Haftu H.

17

Image addition
Adding

a value to each
image pixel value can
be used to achieve the
following effects:
Contrast adjustment:
Adding a positive
constant value C to each
pixel location increases
its value and, hence, its
brightness.
Blending :Adding images
together produces a
composite image of both
input images. This can be
used to produce blending
effects using weighted
addition.
3/20/16

Prepared By: Haftu H.

18

Matlab code

3/20/16

Prepared By: Haftu H.

19

Image subtraction
Subtracting

a constant value from


each pixel (like addition) can also
be used as a basic form of
contrast adjustment.
Subtracting one image from
another shows us the difference
between images.
If we subtract two images in a
video sequence then we get a
difference image (assuming a
static camera) which shows the
movement or changes that have
occurred between the frames in
the scene (e.g. Figure ).
This can be used as a basic form
of change/ movement detection in
video sequences.
3/20/16 Prepared By: Haftu H.

20

Matlab code

A useful variation on subtraction is the absolute difference Ioutput


= |IA-IB| between images .This avoids the potential problem of
integer overflow when the
difference becomes negative.

3/20/16

Prepared By: Haftu H.

21

Image multiplications and division


Multiplication

and division can be used as a


simple means of contrast adjustment and
extension to addition/subtraction (e.g. reduce
contrast to 25% = division by 4; increase
contrast by 50% = multiplication by 1.5).
This procedure is sometimes referred to as
image color scaling.
Similarly, division can be used for image
differencing, as dividing an image by another
gives a result of 1.0 where the image pixel
values are identical and a value not equal to
1.0 where differences occur.
However, image differencing using subtraction
is computationally more efficient.
3/20/16

Prepared By: Haftu H.

22

Matlab code

3/20/16

Prepared By: Haftu H.

23

Challenges?
For

all arithmetic operations between


images we must ensure that the resulting
pixel values remain within the available
integer range of the data type/size
available.
For instance, an 8-bit image (or threechannel 24-bit color image) can represent
256 values in each pixel location.
Integer overflow will occur and the value
will ordinarily wrap around to a low value.
This is commonly known as saturation in
the image space: the value exceeds the
representational capacity of the image.
3/20/16

Prepared By: Haftu H.

24

solutions
Three

principal ways:

add 255 to every pixel then divide by


2.
fast and simple but less accurate .

Take the minimum value form the


second image the add its negative every
other pixels. Then multiply every pixel
by 255/max factor.
more complex and difficult.

Truncate ever over flow values to 255.


matlab codes we saw here use this method.

3/20/16

Prepared By: Haftu H.

25

Applications
In

the area of medical imaging


called mask radiography.
For change detection (image
segmentation).
In astronomy (by using averaging
technique).

3/20/16

Prepared By: Haftu H.

26

Logical operation
We

can perform standard logical


operations between images such as
NOT, OR, XOR and AND.
In general, logical operation is
performed between each
corresponding bit of the image pixel
representation (i.e. a bit-wise
operator).

3/20/16

Prepared By: Haftu H.

27

->NOT Operation
This

inverts the image


representation. In the
simplest case of a binary
image, the (black)
background pixels become
(white) foreground and
vice versa.
For grey scale and color
images, the procedure is
to replace each pixel
value Iinput(i,j) as follows:
Ioutput(i,j) = MAX-Iinput(i,j)
If we consider a 8 bit
image, MAX = 255.
3/20/16

Prepared By: Haftu H.

28

Contd
Similar

operations are done in


OR, AND, NOR, NAND, NXOR,
XOR, etc.
They are applicable for detecting
objects which have moved b/n
frames.

3/20/16

Prepared By: Haftu H.

29

Matlab code for XOR operation.

3/20/16

Prepared By: Haftu H.

30

Individual assignment
Water

mark some texts in an


image using XOR operation.

3/20/16

Prepared By: Haftu H.

31

3.3 Geometric operations


The

need for geometric manipulation of


images appears in many image processing
applications.
The removal of optical distortions
introduced by a camera, the geometric
warping of an image to conform to some
standard reference shape and the
accurate registration of two or more
images are just a few examples requiring
a mathematical treatment involving
geometric concepts.
Inextricably related to our discussion of
geometry in images is the notion of shape.
3/20/16

Prepared By: Haftu H.

32

Contd
Translating

an object from one place to


another, rotating it or scaling (magnifying) it
are all operations which change the objects
shape vector coordinates but do not change
its essential shape.
Shape is all the geometrical information that
remains after location, scale and rotation
effects have been filtered out from an object.
A geometric transformation (also known as a
spatial transformation) modifies the spatial
relationship between pixels in an image,
mapping pixel locations in an moving image to
new locations in an output image.
3/20/16

Prepared By: Haftu H.

33

Contd
Shape

is preserved under the linear


operations of scaling, translation
and rotation.

3/20/16

Prepared By: Haftu H.

34

3.3.1 image resizing


To

resize an image, use the imresize function.


When you resize an image, you specify the
image to be resized and the magnification
factor.
To enlarge an image, specify a magnification
factor greater than 1.
To reduce an image, specify a magnification
factor between 0 and 1.
For example, the command below increases the
size of an image by 1.25 times.
I = imread('circuit.tif');
J = imresize(I,1.25);
imshow(I)
figure, imshow(J)
3/20/16

Prepared By: Haftu H.

35

Contd
You

can specify the size of the


output image by passing a vector
that contains the number of rows
and columns in the output image.
If the specified size does not
produce the same aspect ratio as
the input image, the output image
will be distorted.
If you specify one of the elements
in the vector as NaN, imresize
calculates the value for that
dimension to preserve the aspect
3/20/16

Prepared By: Haftu H.

36

Contd

This

example creates an output


image with 100 rows and 150
columns.
I = imread('circuit.tif');
J = imresize(I,[100 150]);
imshow(I)
figure, imshow(J)
To perform the resizing required for
multiresolution processing, use the
impyramid function.
3/20/16

Prepared By: Haftu H.

37

Specify the Interpolation Method


Interpolation

is the process used to estimate an


image value at a location in between image
pixels.
When imresize enlarges an image, the output
image contains more pixels than the original
image.
The imresize function uses interpolation to
determine the values for the additional pixels.
B = imresize(A, [numrows numcols]) returns
image B that has the number of rows and
columns specified by [numrows numcols].
Either numrows or numcols may be NaN, in
which case imresize computes the number of
rows or columns automatically to preserve the
image aspect ratio.
3/20/16

Prepared By: Haftu H.

38

Prevent Aliasing by Using Filters


When

you reduce the size of an


image, you lose some of the
original pixels because there are
fewer pixels in the output image
and this can cause aliasing.
Aliasing that occurs as a result of
size reduction normally appears as
stair-step patterns (especially in
high contrast images), or as moir
(ripple-effect) patterns in the output
image.
3/20/16

Prepared By: Haftu H.

39

Rotate an Image
To

rotate an image, use the imrotate


function. When you rotate an image, you
specify the image to be rotated and the
rotation angle, in degrees. If you specify a
positive rotation angle, imrotate rotates the
image counterclockwise; if you specify a
negative rotation angle, imrotate rotates
the image clockwise.
By default, imrotate creates an output
image large enough to include the entire
original image.
Pixels that fall outside the boundaries of
the original image are set to 0 and appear
as a black background in the output image.
3/20/16

Prepared By: Haftu H.

40

Contd
This

example rotates an image 35


counterclockwise and specifies
bilinear interpolation.
I = imread('circuit.tif');
J = imrotate(I,35,'bilinear');
imshow(I)
figure, imshow(J)

3/20/16

Prepared By: Haftu H.

41

Translate an Image
This

example shows how to


perform a translation
operation on an image
using the imtranslate
function.
A translation operation
shifts an image by a
specified number of pixels
in either the x or y
direction, or both.
Read image. The size of the
image is 256-by-256 pixels.
By default, imshow displays
the image with the corner
at 0,0.
3/20/16

Prepared By: Haftu H.

42

Contd

Translate

the image, shifting the


image by 15 pixels in the x direction
and 25 pixels in the y direction.
Note that, by default, imtranslate
displays the translated image within
the boundaries (or limits) of the
original 256-by-256 image.
This results in some of the translated
image being clipped.
To see the entire translated image,
use the 'OutputView' parameter
(shown in the following step).
3/20/16

Prepared By: Haftu H.

43

Contd
J = imtranslate(I,[15, 25]);
figure;
imshow(J);
Use the 'OutputView'
parameter set to 'full' to
adjust the display to show
the entire translated
image.
J=imtranslate(I,
[15,25],'OutputView','full');

figure;
imshow(J);
3/20/16

Prepared By: Haftu H.

44

Shape and homogeneous T.


We

can take the Euclidean coordinates


Coordinates
of the new
image

Coordinates of
the original image

J(x, y) = I(T(x, y))


E.g:
J(x, y) = I(x+2, y)
J(0,0) = I(2,0)
J(-2,0) = I(0,0)

3/20/16

Prepared By: Haftu H.

45

Contd
Scaling

e.g:

J(x, y) = I(2x, 2y)

J(x, y) = I(1/3x, 1/3y)


J(x, y) = I(2x, 1/2y)
3/20/16

Prepared By: Haftu H.

46

Contd
Reflecting

e.g:

J(x, y) = I(-x, y)
J(x, y) = I(x, -y)

3/20/16

Prepared By: Haftu H.

47

Linear transformation

It

is common for scale + Flip +


shift to combine in to a 2D image.
Such transformations are called
linear.

Coordinates of the
transformed image

Coordinates of the
original image

3/20/16

Prepared By: Haftu H.

48

Contd
Translation:

Scaling:

Flipping:

3/20/16

Prepared By: Haftu H.

49

Contd
Rotation:

3/20/16

Prepared By: Haftu H.

50

Contd
Any

combination of shift, scale and


rotation is called similarity
transformation.
preserves parallel lines.
preserves shapes, and angles.

3/20/16

Prepared By: Haftu H.

51

contd
Shear:

How?

This

is called horizontal shear.


What about its vertical shear?
Try again both shear mechanism?
3/20/16

Prepared By: Haftu H.

52

Contd
Affine:

the

affine transform are chosen to


effect the operations of translation,
rotation, scaling and shearing.
This transform can scale, translate,
rotate or shear set points depending
on the values chosen for T.
3/20/16

Prepared By: Haftu H.

53

summery

3/20/16

Prepared By: Haftu H.

54

projective transform
If

a camera captures an image of a 3-D


object, then, in general, there will be a
perspective mapping of points on the object
to corresponding points in the image.
Pairs of points that are the same distance
apart on the object will be nearer or further
apart in the image depending on their
distance from the camera and their
orientation with respect to the image plane.
In a perspective transformation we consider
3-D world coordinates (X; Y; Z) which are
arbitrarily distributed in 3-D space and
mapped (typically) to the image plane of a
camera.
3/20/16

Prepared By: Haftu H.

55

Contd
However,

in those situations in
which the points of interest in the
object can be considered as
confined (either actually or
approximately) to a plane and we
are interested in the mapping of
those object points into an
arbitrarily oriented image plane,
the required transformation is
termed projective.

3/20/16

Prepared By: Haftu H.

56

Contd
Since

this mapping is
constrained at four 2-D
points, there are eight
coordinates and thus
eight degrees of freedom
in a projective transform.
It is possible to show
that the general form of
the 2-D projective
transformation matrix in
a homogeneous
coordinate system is
given by:
3/20/16

Prepared By: Haftu H.

57

Contd
the

transformed (projected)
coordinates in the image plane are
related to the world points through
matrix multiplication as:

Note

that there are eight degrees


of freedom in the projective matrix
(not nine), since the parameters are
constrained by the relation.
3/20/16

Prepared By: Haftu H.

58

Matlab code

3/20/16

Prepared By: Haftu H.

59

Matlab output

3/20/16

Prepared By: Haftu H.

60

Warp transformation
mapping

of intensity values from


one spatial distribution into another
spatial distribution is commonly
known as image warping.
The image which is to be
transformed is termed the input.
The reference image is termed the
base image and the base
landmarks effectively define the
target spatial coordinates to which
the input landmarks must be
transformed.
3/20/16

Prepared By: Haftu H.

61

Contd
pair

of corresponding landmarks in the


input and base images are referred to
as tie-points (as they are in a certain
sense tied to each bother).
the basic steps in the overall procedure
are:
1. Locate an equal number of matching
landmarks on the image pair (x0i ; y0i
for the base image and xi; yi for the
input). Note that matching landmarks
are often called tie-points and we will
use these terms interchangeably.
3/20/16

Prepared By: Haftu H.

62

Contd

2. Define a chosen functional form to


map coordinates from the input to
the base.
x = f(x, y) and y = g(x, y)
3. Write a system of equations each
of which constrains the required
mapping from a tie-point in the
input to its corresponding tie-point
in the base. Thus, for N tie-points,
we have:

3/20/16

Prepared By: Haftu H.

63

Contd
4. The chosen functional forms f (x,
y) and g(x, y) will be characterized
by one or more free (fit)
parameters. We solve the system of
equations for the free parameters.
5. For every valid point in the base
image, calculate the corresponding
location in the input using the
transforms f and g and copy the
intensity value at this point to the
base location.
3/20/16

Prepared By: Haftu H.

64

See z process

3/20/16

Prepared By: Haftu H.

65

e.g

3/20/16

Prepared By: Haftu H.

66

Matlab code

3/20/16

Prepared By: Haftu H.

67

Fourier Transform
Back ground:
the Frech mathematician Jean Baptiste Joseph Fourier was
born in 1768.
Basically, Fourier's contribution in this particular field
states that any function that repeats itself can be
expressed as the sum of sine and cosine of different
frequencies each multiplied by different coefficients (we
call now this a fourier series.)
Even functions that are not periodic (but whose area
under the curve is finite) can be expressed as the integral
of sine and cosine multiplied by weighting function.
The function can be reconstructed(recovered) completely
via an inverse process with no lose of information.
Fourier transform is applicable here, for image
enhancment approach.

3/20/16

Prepared By: Haftu H.

68

Fourier transform and frequency domain


The

fourier transform, F(u), of a


single variable, continuous function,
f(x) is define by the equation:

Where

, conversely, given F(u),


we can obtain f(x), by inverse
fourier transform:

3/20/16

Prepared By: Haftu H.

69

Contd
Both

equations are easily extended


to two variables, u and v.

And,

similarly for inverse


transform;

But

our interest is in discrete


function?
3/20/16

Prepared By: Haftu H.

70

Discrete Fourier Transform


Discrete

fourier transform of single


variable function is given as: where
x=0,1, .m-1.

We

can obtain the original function


f(x) back.

Where
Therefore,
3/20/16

Prepared By: Haftu H.

71

The two dimensional DFT and its


inverse
The DFT of two dimensional image
f(x, y) of size MXN is given by:

And

its inverse as:

Where

variables u and v are


frequencies and x and y are image
variables.
3/20/16

Prepared By: Haftu H.

72

Contd

in the analysis of complex


numbers and we find it
convenient sometimes to
express F(u) in polar
coordinates:

As

Is

called the magnitude or


spectrum of the fourier
transform, and
3/20/16

Prepared By: Haftu H.

73

Contd
Finally

the relationship b/n the


samples of in the spatial and
frequency domain:

3/20/16

Prepared By: Haftu H.

74

You might also like