Lesson 3 PERSPECTIVE TRANSFORMATION
Lesson 3 PERSPECTIVE TRANSFORMATION
11/30/2019 Lesson 2 2
5 frames of reference
• In order to analyze a 3D world/image/scene,
5 different frame of references are required.
– Object
– World
– Camera
– Image
– Pixel
11/30/2019 Lesson 2 3
• Object coordinate frame
– Object coordinate frame is used for modeling
objects.
– For example, checking if a particular object is in a
proper place with respect to the other object.
– It is a 3D coordinate system.
11/30/2019 Lesson 2 4
• Camera coordinate frame
– Camera co-ordinate frame is used to relate objects
with respect to the camera.
– It is a 3D coordinate system.
• Image coordinate frame
– It is not a 3D coordinate system, rather it is a 2D
system.
– It is used to describe how 3D points are mapped
in a 2D image plane.
• Pixel coordinate frame
– It is also a 2D coordinate system.
– Each pixel has a value of pixel co ordinates.
11/30/2019 Lesson 2 5
Transformation between these 5 frames
• Where
– Y = 3D object
– y = 2D Image
– f = focal length of the camera
– Z = distance between object and the camera
11/30/2019 Lesson 2 7
• There are two different angles formed in this
transform which are represented by Q. They are:
1) ) Where minus denotes that image is inverted
2)
• Comparing these two equations we get
• From this equation, we can see that when the
rays of light reflect back after striking the object,
passed in the camera, an inverted image is
formed.
11/30/2019 Lesson 2 8
Calculating the size of image formed
• Suppose an image has been taken of a person 5m
tall, and standing at a distance of 50m from the
camera, and we have to tell the size of the image
of the person, with a camera of focal length 50mm.
• The focal length is in millimeter, so convert
everything in millimeter.
– Y = 5000 mm.
– f = 50 mm. = -5 mm.
– Z = 50000 mm.
• Minus sign indicates that the image is inverted.
11/30/2019 Lesson 2 9
CONCEPT OF BITS PER PIXEL
• Bpp or bits per pixel denotes the number of
bits per pixel. The number of different colors
in an image depends on the depth of color or
bits per pixel.
• Number of different colors
Bits per pixel Number of colors
1 bpp 2 colors
2 bpp 4 colors
3 bpp 8 colors
4 bpp 16 colors
5 bpp 32 colors
6 bpp
11/30/2019 64 colors Lesson 2 10
• Shades
11/30/2019 Lesson 2 11
• Gray color:
• Gray color is the midpoint of black and white.
• In case of 8bpp, the pixel value that denotes
gray color is 127 or 128bpp if you count from
1, not from 0.
11/30/2019 Lesson 2 12
Image storage requirements
• Image size
– The size of an image depends upon three things.
• Number of rows
• Number of columns
• Number of bits per pixel
• Size of an image = rows * cols * bpp
11/30/2019 Lesson 2 13
TYPES OF IMAGES
• The binary image
– The binary image as it name states, contain only two pixel
values.
– 0 and 1.
• 0 refers to black color and 1 refers to white color. It is
also known as Monochrome.
• Black and white image:
• The resulting image that is formed hence consist of
only black and white color and thus can also be
called as Black and White image.
11/30/2019 Lesson 2 14
– No gray level
– In Binary image that there is no gray level in it. Only
two colors that are black and white are found in it.
– Format: Binary images have a format of PBM
(Portable bitmap)
• 2, 3, 4,5, 6 bit color format
• The images with a color format of 2, 3, 4, 5 and 6
bit are not widely used today. They were used in
old times for old TV displays, or monitor displays.
• But each of these colors have more than two gray
levels, and hence has gray color unlike the binary
image.
• In a 2 bit 4, in a 3 bit 8, in a 4 bit 16, in a 5 bit 32,
in a 6 bit 64 different colors are present.
11/30/2019 Lesson 2 15
• 8 bit color format
– 8 bit color format is one of the most famous image
format.
– It has 256 different shades of colors in it. It is
commonly known as Grayscale image.
– The range of the colors in 8 bit vary from 0-255.
Where 0 stands for black, and 255 stands for white,
and 127 stands for gray color.
– This format was used initially by early models of the
operating systems - UNIX and the early color
Macintoshes.
• Format: The format of these images are PGM
(Portable Gray Map)
11/30/2019 Lesson 2 16
• 16 bit color format
– It is a color image format.
– It has 65,536 different colors in it.
– It is also known as High color format.
– It has been used by Microsoft in their
systems that support more than 8 bit color
format.
11/30/2019 Lesson 2 17
• The distribution of color in a color image is not
as simple as it was in grayscale image.
• A 16 bit format is actually divided into three
further formats which are Red, Green and
Blue. The famous RGB format.
11/30/2019 Lesson 2 18
• Distribution of 16 bit is done as: 5 bits for R, 6
bits for G, 5 bits for B.
• The additional bit is added to the green bit,
because green is the color which is most
soothing to eyes in all of these three colors.
• Another distribution of 16 bit format is:
• 4 bits for R, 4 bits for G, 4 bits for B, 4 bits for
alpha channel.
• Or 5 bits for R, 5 bits for G, 5 bits for B, 1 bits
for alpha channel.
11/30/2019 Lesson 2 19
• 24 bit color format
– 24 bit color format also known as true color format.
Like 16 bit color format, in a 24 bit color format, the
24 bits are distributed equally between three
different channels of Red, Green and Blue.
– 8 bits for R, 8 bits for G, 8 bits for B.
11/30/2019 Lesson 2 20
• Unlike a 8 bit gray scale image, which has one
matrix behind it, a 24 bit image has three
different matrices of R, G, B. RGB components
10 10 16 28
9 656 7026
56 43
37 78
32 99 54 70 67
96 56
15 256013 902296
67
• Format 21 54 47 42
32 158587 853943 92
54 65 65 39
– It is the most common used format. 32 65 87 99
11/30/2019 Lesson 2 21
• COLOR CODES CONVERSION
• Different color codes
– Binary color format
– Black-0,0,0
– White-255,255,255
– Red-255,0,0
– Gray color-128,128,128
• The gray color is actually the midpoint.
• In an 8-bit format, the midpoint is 128 or 127.
• In this case we chose 128.
11/30/2019 Lesson 2 22
• CMYK color model:
– CMYK is another color model where c stands for
cyan, m stands for magenta, y stands for yellow,
and k for black.
– CMYK model is commonly used in color printers.
• Color: Cyan-0,255,255
– Cyan color is formed from the combination of
Green and blue.
– Magenta-255,0,255
– Magenta color is formed from the combination of
Red and Blue.
11/30/2019 Lesson 2 23
• Conversion from RGB to Hex code:
– To convert RGB to Hex:
• Take a color. E.g: White = 255,255,255.
• Take the first portion e.g 255.
• Divide it by 16.
• Take the two numbers below line, the factor, and the
remainder.
• In this case it is 15 which is FF.
• Repeat the step 2 for the next two portions.
• Combine all the hex code into one.
– Answer: #FFFFFF
11/30/2019 Lesson 2 24
• Conversion from Hex to RGB:
– Take a Hex number. E.g: #FFFFFF
– Break this number into 3 parts: FF FF FF
– Take the first part and separate its components: F F
– Convert each of the part separately into binary:
1111 1111
– Now combine the individual binaries into one:
11111111
– Convert this binary into decimal: 255
– Now repeat step 2, two more times.
– Answer: 255,255,255
11/30/2019 Lesson 2 25
• Common colors and their Hex code
Color Hex Code
Black #000000
White #FFFFFF
Gray #808080
Red #FF0000
Green #00FF00
Blue #0000FF
Cyan #00FFFF
Magenta #FF00FF
Yellow #FFFF00
11/30/2019 Lesson 2 26
• RGB TO GRAYSCALE CONVERSION
• Converting RGB color Image to Gray scale
image
• Two methods are:
– Average method
– Weighted method or luminosity method
• Average method
– Take the average of three colors.
– Grayscale = R+G+B/3
11/30/2019 Lesson 2 27
• Example
11/30/2019 Lesson 2 28
• Problem
– This problem arise due to the fact, that we take
average of the three colors. Since the three
different colors have three different wavelength
and have their own contribution in the formation
of image, so we have to take average according to
their contribution.
– What was done was, 33% of Red, 33% of Green,
33% of Blue, each of the portion has same
contribution in the image. But in reality that's not
the case.
• The solution to this is luminosity/weighted
average method.
11/30/2019 Lesson 2 29
• Weighted method or luminosity method
– Since red color has more wavelength of all the
three colors, and green is the color that has not
only less wavelength than red color but also green
is the color that gives more soothing effect to the
eyes.
– Decrease the contribution of red, increase the
contribution of the green color, and put blue color
contribution in between these two.
• So the new equation that form is:
– New grayscale image = (0.3∗R+ 0.59∗G + 0.11∗B).
– Red contribute 30%, Green 59% and Blue 11%.
11/30/2019 Lesson 2 30
• Applying this equation to the image, we get
this
11/30/2019 Lesson 2 32
• Example
11/30/2019 Lesson 2 33
• Histogram of an image
• Histogram of an image, like other histograms
also shows frequency.
• An image histogram, shows frequency of
pixels intensity values.
• In an image histogram, the x axis shows the
gray level intensities and the y axis shows the
frequency of these intensities.
11/30/2019 Lesson 2 34
• Example
11/30/2019 Lesson 2 35
• Applications of Histograms in Image
Processing
a)Analysis of the image. We can predict the
appearance of an image by just looking at its
histogram.
– Its like looking an x ray of a bone of a body.
b) Brightness purposes. The histograms has wide
application in image brightness. Not only in
brightness, but histograms are also used in
adjusting contrast of an image.
c) Equalizing an image.
d) Thresholding. This is mostly used in computer
vision.
11/30/2019 Lesson 2 36
BRIGHTNESS AND CONTRAST
• Brightness
– Brightness is a relative term. It depends on your
visual perception.
– The amount of energy output by a source of light
relative to the source we are comparing it to.
– In some cases we can easily say that the image is
bright, and in some cases, it's not easy to
perceive.
11/30/2019 Lesson 2 37
• Making an Image Brighter
– Brightness can be simply increased or decreased
by simple addition or subtraction, to the image
matrix.
– Consider this black image of 5 rows and 5 columns
11/30/2019 Lesson 2 39
• Contrast
– Contrast is the difference between maximum and
minimum pixel intensity in an image.
– Consider the final image1 in brightness.
11/30/2019 Lesson 2 40
• The maximum value in this matrix is 100.
• The minimum value in this matrix is 100.
• Contrast = maximum pixel intensity subtracted
by minimum pixel intensity
= 100 subtracted by 100 = 0
0 means that this image has 0 contrast.
11/30/2019 Lesson 2 41
IMAGE TRANSFORMATIONS
• Transformation is a function that maps one set
to another set after performing some
operations.
• Digital Image Processing system
– In digital image processing system the input is an
image and output is an image too.
– And the system perform some processing on the
input image and gives its output as a processed
image. It is shown below.
11/30/2019 Lesson 2 42
• The function applied inside this digital system
process an image and convert it into output
can be called as transformation function.
11/30/2019 Lesson 2 43
• Image transformation.
– Consider this equation Gx,y = T{ fx,y}
– In this equation, Fx,y = input image on which
transformation function has to be applied.
– Gx,y = the output image or processed image.
– T is the transformation function.
– This relation between input image and the
processed output image can also be represented
as.
– s = T r, where r is actually the pixel value or gray
level intensity of fx,y at any point.
– And s is the pixel value or gray level intensity of
gx,y at any point.
11/30/2019 Lesson 2 44
• Consider this transformation function.
11/30/2019 Lesson 2 46
• In the graph, there is a straight transition line
between input image and output image.
• It shows that for each pixel or intensity value of input
image, there is a same intensity value of output
image.
• That means the output image is exact replica of the
input image.
• It can be mathematically represented as:
– gx,y = fx,y
• The input and output image in this case are as shown
below.
11/30/2019 Lesson 2 47
• HISTOGRAM SLIDING
– In histogram sliding, we just simply shift a
complete histogram rightwards or
leftwards.
– Due to shifting or sliding of histogram
towards right or left, a clear change can be
seen in the image.
– Histogram sliding can be used for
manipulating brightness.
11/30/2019 Lesson 2 48
• Increasing brightness using histogram sliding
11/30/2019 Lesson 2 49
• To brighten the image, slide its histogram
towards right, or towards whiter portion.
• Add atleast a value of 50 to this image.
• It can be seen from the histogram, that the
image also has 0 pixel intensities, that are
pure black.
• Adding 50 to 0, shifts all the values that lies at
0 intensity to 50 intensity and all the rest of
the values are shifted accordingly.
11/30/2019 Lesson 2 50
• Comparing the images
11/30/2019 Lesson 2 52
HISTOGRAM STRETCHING
• This enables contrast enhancement.
• There are two methods of enhancing contrast.
– The first one is called Histogram stretching that
increase contrast.
– The second one is called Histogram equalization
that enhance contrast.
11/30/2019 Lesson 2 53
• Increasing the contrast of the image
• To stretch contrast use the following formula
11/30/2019 Lesson 2 57
• Consider this matrix
1 2 7 5 6
7 2 3 4 5
0 1 5 7 3
1 2 5 6 7
6 1 0 3 4
• Its PMF is 0 2 2/25
1 4 4/25
2 3 3/25
3 3 3/25
4 2 2/25
5 4 4/25
6 3 3/25
7 4 4/25
• Note that the sum of the count must be equal to total number
of values.
11/30/2019 Lesson 2 58
• Calculating PMF from histogram
11/30/2019 Lesson 2 59
• So the PMF of the histogram is this.
11/30/2019 Lesson 2 60
• CDF- cumulative distributive function.
– It is a function that calculates the cumulative sum of all the
values that are calculated by PMF.
– It basically sums the previous one.
– To compute CDF, simply keep the first value as it is, and then in
the 2nd value, add the first one and so on.
– For this PMF, its CDF is
– From the graph , the first value of PMF
remain as it is. The second value of PMF is
added to the first value and placed over 128.
The third value of PMF is added to the second
value of CDF, that gives 110/110 which is
equal to 1
-The function is growing monotonically which is necessary
condition for histogram equalization.
-PMF and CDF are used in histogram equalization
11/30/2019 Lesson 2 61
• Histogram equalization
– Histogram equalization is used for enhancing the
contrast of the images.
– In the histogram equalization, the first and the
second step are PMF and CDF.
– Since in histogram equalization, we have to equalize
all the pixel values of an image.
– PMF helps us calculating the probability of each pixel
value in an image.
– CDF gives us the cumulative sum of these values.
– CDF is multiplied by gray levels, to find the new pixel
intensities, which are mapped into old values, and
the histogram is equalized.
11/30/2019 Lesson 2 62
• HISTOGRAM EQUALIZATION
• Histogram equalization is used to enhance
contrast.
• It is not necessary that contrast will always be
increased in this.
• There may be some cases where histogram
equalization can be worse.
• In that cases the contrast is decreased.
11/30/2019 Lesson 2 63
• Example
11/30/2019 Lesson 2 64
• Calculate CDF according to gray levels
• Lets for instance consider this, that the CDF
calculated in the second step looks like this.
Gray Level Value CDF
0 0.11
1 0.22
2 0.55
3 0.66
4 0.77
5 0.88
6 0.99
7 1
• Then in this step multiply the CDF value with
Graylevels (minus1).
11/30/2019 Lesson 2 65
• Considering we have an 3 bpp image. Then
number of levels we have are 8. And 1
subtracted from 8 is 7. So multiply CDF by 7. The
results after multiplying is as follows:
Gray Level Value CDF CDF * Levels−1
0 0.11 0
1 0.22 1
2 0.55 3
3 0.66 4
4 0.77 5
5 0.88 6
6 0.99 6
7 1 7
11/30/2019 Lesson 2 66
• Next is the last step, where we map the new
gray level values into number of pixels.
• Assuming the old gray levels values had these
number of pixels.
Gray Level Value Frequency
0 2
1 4
2 6
3 8
4 10
5 12
6 14
7 16
11/30/2019 Lesson 2 67
• Map the new values to them gives
Gray Level Value New Gray Level Value Frequency
0 0 2
1 1 4
2 3 6
3 4 8
4 5 10
5 6 12
6 6 14
7 7 16
11/30/2019 Lesson 2 68
• Histogram Equalization Image
• Histogram Equalization
11/30/2019 Lesson 2 69
• Comparing both the histograms and images
• From the images, the new image contrast has been enhanced
and its histogram has also been equalized.
• There is also one important thing to be noted that during
histogram equalization the overall shape of the histogram
changes, where as in histogram stretching the overall shape of
histogram remains same. Lesson 2
11/30/2019 70
• GRAY LEVEL TRANSFORMATION
• Image enhancement
• Enhancing an image provides better contrast
and a more detailed image as compared to
non enhanced image.
• Image enhancement has very many
applications.
– It is used to enhance medical images, images
captured in remote sensing, images from satellite
e.t.c
11/30/2019 Lesson 2 71
• The transformation function has been given
below
• s=Tr
– 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.
– Image enhancement can be done through gray
level transformations.
11/30/2019 Lesson 2 72
• Gray level transformation
• There are three basic gray level transformation.
– Linear
– Logarithmic
– Power – law
11/30/2019 Lesson 2 73
• Linear transformation
• 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.
• Hence is called identity
transformation.
11/30/2019 Lesson 2 74
• Negative transformation
• Negative transformation is an inverse 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
• Input Image Output Image
11/30/2019 Lesson 2 75
• In this case the following transition has been done.
• s = L–1– r
• since the input image is an 8 bpp image, so the
number of levels in this image are 256. Putting 256 in
the equation, we get this
• s = 255 – r
• So each value is subtracted from 255.
• The lighter pixels become darker and the darker
picture becomes lighter.
• It results in an image which is negative (inverse).
11/30/2019 Lesson 2 76
• Logarithmic transformations
• Logarithmic transformation further contains two
type of transformation. Log transformation and
inverse log transformation.
• Log transformation
• The log transformations can be defined by this
formula - s = c logr+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.
11/30/2019 Lesson 2 77
• During log transformation, the dark pixels in an image
are expanded as compared to the higher pixel values.
• The higher pixel values are kind of compressed in log
transformation. This result in image enhancement.
• The value of c in the log transform adjust the kind of
enhancement you are looking for.
• Input Image Log Transform Image
11/30/2019 Lesson 2 80
• Correcting gamma.
• s=cr^γ
• s=cr^1/2.5
• The same image but with different gamma
values has been shown here.
• Gamma=10 Gamma=8 Gamma=6
11/30/2019 Lesson 2 81