0% found this document useful (0 votes)
48 views121 pages

Computer Vision-Lec 02

Uploaded by

laiba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views121 pages

Computer Vision-Lec 02

Uploaded by

laiba
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 121

Computer Vision

Lec 02
What is image?
Image is collection of pixels.
What is pixel?
Pixel is smallest unit in an image which contain color value.
● A good image contain approximately 300 PPI(Pixel Per Inch)
OR DPI(Dot Per Inch)
What is video?
Video is collection of images.
What is image?

An image may be defined as a two dimensional function f(x,y)


where x and y are spatial coordinates and amplitude of f at
any pair of coordinates (x,y) is called the intensity or
Graylevel of the image at that point.
Types of Image

Image

Single channel 3-channel image

Grey Scale RGB(Red Green


Black white image Blue)
image
Representation of Digital Image
● Image is represented in 2-D function f(x,y)
● x,y are spatial coordinate
● f(x,y) show the intensity or grey level of image at that point
● f(x,y) are all finite and discrete quantities are known as digital image

Suppose size of image is(4,5) {width,height} width


f(0,0) f(1,0) f(2,0) f(3,0)

f(0,1) f(1,1) f(2,1) f(3,1)


height
f(0,2) f(1,2) f(2,2) f(3,2)

f(0,3) f(1,3) f(2,3) f(3,3)


pixel
f(0,4) f(1,4) f(2,4) f(3,4)
Image Formats
Suppose size of image is(100,150) {width,height}

Format No. of pixels No. of bits Grey Level

Black white 100*150 100*150*1 (0 or 1)= 2

Grey scale 100*150 100*150*8 (0-255) = 2^8

Color image 100*150*3 100*150*3*8 (0-255)=2^24


import cv2
#cv2.imread(path,flag)
img1=cv2.imread("1.jpeg")
img1=cv2.resize(img1,(3,4)) #3=width(column(x), 4=height(row(y))
print(img1)
print("pixel intensity of x=1,y=1",img1[1,1])
print("shape",img1.shape) x(column)=0,y(row)=0
cv2.imshow("picture",img1)
cv2.waitKey()
[
[ [128 68 159] [122 91 218] [ 36 104 73] ] x(column)=0,y(row)=0
[ [ 65 101 107] [173 234 231] [ 70 137 92] ]
[ [ 9 8 203] [ 46 74 72] [ 90 67 201] ]
[ [ 48 120 73] [ 9 34 96] [ 46 82 89] ]
]
pixel intensity of x=1,y=1 [173 234 231]
shape (4, 3, 3) #4=rows,3=col,3=channel
import cv2

#cv2.imread(path,flag)

img1=cv2.imread("1.jpeg",0) # 0 represent grayscale image

img1=cv2.resize(img1,(3,4))#3=width(column(x), 4=height(row(y))

print(img1)

print("pixel intensity of x=1,y=1",img1[1,1])

cv2.imshow("picture",img1)

cv2.waitKey() x(column)=0,y(row)=1
[
[103 132 87]
[ 99 226 116]
[ 66 70 110]
[ 98 49 80]
]
pixel intensity of x=1,y=1 226
Sampling and Quantization
An image may be continuous with respect to the x- and y-coordinates, and also in
amplitude.
To digitize it, we have to sample the function in both coordinates and also in
amplitude.
● Digitizing the coordinate values is called sampling.
○ It determines the spatial resolution of the digitized images.
● Digitizing the amplitude values is called quantization.
○ It determines the number of grey levels in the digitized images.
Quantization Level

● 8 bit quantization: 28=256 gray levels (0: black, 255: white)


● Binary (1 bit quantization):2 gray levels (0: black, 1: white)
Gray Scale Values (Range 0-255)
Pixels Neighborhood

Any pixel can be represented by

x=column y
y=row
y+1 x-1,y+1 x,y+1 x+1,y+1

x-1,y x,y x+1,y


y
x-1,y-1 x,y-1 x+1,y-1
y-1
x
x-1 x x+1
N₄(p) Neighborhood
Any pixel can be represented by

x=column y
y=row
y+1 x,y+1

x-1,y x,y x+1,y


y
x,y-1
y-1
x
x-1 x x+1
NٖD(p) Neighborhood
Any pixel can be represented by

x=column y
y=row
y+1 x-1,y+1 x+1,y+1

x,y
y
x-1,y-1 x+1,y-1
y-1
x
x-1 x x+1
Nٖ8(p) Neighborhood
Any pixel can be represented by

x=column y
y=row
y+1 x-1,y+1 x,y+1 x+1,y+1
Union of
x-1,y x,y x+1,y
y
Nٖ4(p) and NٖD(p)
x-1,y-1 x,y-1 x+1,y-1
y-1
x
x-1 x x+1
ADJACENCY
● Let V be the set of intensity values used to define adjacency
4-adjacency

Two pixels p and q with values from V are 4-adjacent if

● q is in the set Np(4).

In a binary image, V = {1} if we are referring to adjacency of pixels with value 1


8-adjacency
Two pixels p and q with values from V are 8-adjacent if q is in the set N8(p).

54 10 58 8

81 150 2 34

201 200 3 45

7 70 147 56

V={1,2,3,....10}
m-adjacency
Two pixels p and q with values from V are m-adjacent if
● q is in N4(p)
OR
● q is in ND(p) and the set N4(p) ∩ ND(p) has no pixels whose
values are from V.
Fig : A

Fig : A Fig : B Fig : C

Fig : D
Distance Measure
For pixels p, q with coordinates (x,y) , (u,v)

● Euclidean Distance: De(p, q) = [(x-u)2 + (y-v)2]1/2


● City Block Distance: D4(p, q) = |x-u| + |y-v|
● Chess Board Distance: D8(p, q) = max(|x-u|, |y-v|)
City Block Distance

● The pixels with D4 distance ≤ 2 from (x, y) (the center point) form the following
contours of constant distance:
● D4(p, q) = |x-u| + |y-v|
● The pixels with D4 = 1 are the 4-neighbors of (x,y)
1

3
Chess Board Distance

● The pixels with D8 distance ≤ 2 form the following contours of constant


distance
● D8(p, q) = max(|x-u|, |y-v|)
● The pixels with D8 = 1 are the 8-neighbors of the pixel at (x,y)
ARITHMETIC OPERATIONS

Arithmetic operations between two images f(x,y) and g(x,y) are denoted as

Addition : s(x,y) = f(x,y) + g(x,y)

Subtraction: s(x,y) = f(x,y) - g(x,y)

Multiplication: p(x,y) = f(x,y) * g(x,y) (element wise multiplication)

Division: t(x,y) = f(x,y) / g(x,y)


Addition
0 100 10 10 250 5 10 255 15

4 0 10 + 2 0 0 = 6 0 10

8 0 5 0 10 10 8 10 15

Usage:

● Averaging images for noise removal


Image Averaging for Noise Reduction
Subtraction
0 +
100 =
10 10 100 5 0 0 5

4 0 10 2 0 0 2 0 10

8 0 5 0 10 10 8 0 0

Usage:
● Removal of background from images
● Image enhancement
● Image matching
● Moving/displaced object tracking
Removal of background from images
Multiplication and Division

● Multiplication of pixel values by a number greater than one will


brighten the image
● Division by a factor greater than one will darken the image

a) original image b) image multiplied by 2 c) image divided by 2


Example of Image Multiplication
Multiplication of image can be used for superimposing texture on an image
Logical Operator
AND operator
● Logical AND operations are useful for the masking of images.
● binary image acts as a mask removes information from certain parts of the
image.
● This operation can be used to find the similarity white regions of two different
images (it required two images).
AND (^)
OR Operator
Logical OR operations are useful for the

● compositing of images
Not Operator
negative of the original image.
Neighbourhood Operation
Image Enhancement
● is a process to improve the quality of image.
● To highlight the important detail
● To remove noise
Method of image enhancement
● Spatial domain
● Frequency domain
● Combination method
Spatial Domain

● Spatial domain refers to the image plane itself and are


based on direct manipulation of pixels in an image.
● g(x,y) = T(f(x,y))
Method:
○ Point Operations (Intensity Transformation)
○ Histogram based processing
○ Mask Processing
Point Operation
● Enhancement at any point in an image depend on gray level at point.
● S=T(r)
Where
S=value of pixel after processing
T= transformation function
r = value(intensity) of pixel before processing
Method:
○ Contrast Stretching Function
○ Linear Negative Transformation(Image Negative)
Image Negative
Obtain the digit negative of the following 8-bit per
pixel image

139 205 105

141 252 99

201 15 76
Obtain the digit negative of the following 8-bit per
pixel image
116 50 150
L=28 = 256 139 205 105

S=(L-1)-r 114 3 156


141 252 99

r=p(x,y) 201 15 76 54 240 175


Home Task
● Log transformation
● Power law transformation
Mask/Kernel Processing

Instead of taking 1 pixel, we are taking the neighbourhood values.

N4P - 4 Neighbours : (x+1,y),(x-1,y),(x,y+1),(x,y-1)


NDP - 4 Diagonal Neighbours : (x+1,y+1),(x+1,y-1),(x-1,y+1),(x-1,y-1)
N8P - 8 Neighbours : N4P + NDP

Min, Max, Median operation


MASK PROCESSING, MASK FILTERING, SPATIAL
FILTERING
● the terms template, kernel, window, filter, and convolution mask are also used
to denote a mask
● mask is an array of numbers (typically 3x3 or 5x5, etc.)
● mask is usually very small with respect to the processed image
● mask values are called coefficients
● values of coefficients determine the nature of the process

the masks can be designed for noise reduction, edge detection, etc.
Smoothing Filters
● Smoothing filters are used for blurring (removal of small details from
an image prior to large object extraction) and for noise reduction
Low pass Filter:
● Low pass filter always has positive coefficients
● Sum of the coefficients is equal to 1
● It blurs edges
Low Pass filtering
Simple average filters:
Median filtering
● if the objective is to achieve noise reduction rather than blurring, use median
filter.
● less
Spatial image Sharpening
Goals: highlight or enhance details in images.
● To highlight fine detail
● Remove blurring from image
● Highlight edges
Procedure: Based on spatial differentiation.
Applications:
● Photo enhancement
● Medical image visualization
● Industrial defect detection
Spatial Differentiation
● Rate of change of function
● Consider 1-D example
1st derivative
● Must be zero in flat segments (area of constant grey levels)
● Must be non zero at the onset of grey level step or ramp
● Must be non zero along ramps
2nd Derivative
● Must be zero in flat segment
● Must be non zero at the onset and end of a gray level step or ramp
● Must be non zero along ramps of constant slope
1st vs 2nd Derivative comparison

● Must be zero in flat segments ● Must be zero in flat segment


(area of constant grey levels)

● Must be non zero at the onset ● Must be non zero at the onset
of grey level step or ramp and end of a gray level step or
ramp
● Must be non zero along ramps ● Must be non zero along ramps
of constant slope
f(x,y) g(x,y)
Unsharp Mask & High Boost Filtering
Using sequence of linear Spatial filters in order to get sharpening effect.

● Blur
● Subtract from original image
● Add resulting mask to original image
A=K
Horizontal Filter:
Vertical Filter
1st Derivative Filter

● Robert
● Sobel
● Prewitt Filter
Roberts cross-gradient operators.

3*3 region of image


Prewitt Mask

You might also like