Image Moment
M
p
q
=
d
e
f
∑
x
∑
y
x
p
y
q
I
(
x
,
y
)
M_{pq}\xlongequal{def}\sum_x \sum_y x^p y^q I(x, y)
Mpqdefx∑y∑xpyqI(x,y)
so the centroid of image is
(
x
,
y
)
=
(
M
10
M
00
,
M
01
M
00
)
(x,y) = \left( \frac{M_{10}}{M_{00}},\frac{M_{01}}{M_{00}} \right)
(x,y)=(M00M10,M00M01)
compute moments in python:
M = cv2.moments(c)
reference: Image moment
Canny Edge Detection
a multi-stage algorithm
- Noise Reduction
- Gaussian Filter
- Finding Intensity Gradient of the Image
- filter with Sobel Kernel in both horizontal and vertical direction to get first derivative in horizontal direction G x G_x Gx and vetical direcition G y G_y Gy
- G = G x 2 + G y 2 θ = arctan ( G y G x ) G=\sqrt{G_x^2 + G_y^2} \\ \theta = \arctan \left(\dfrac{G_y}{G_x}\right) G=Gx2+Gy2θ=arctan(GxGy)
- Non-maximum Suppression
- what is it: Non-maximum Suppression (NMS)
- Hysteresis Thresholding
- what is it: Standard and Hysteresis Thresholding
- We need two threshold values, minVal and maxVal. Any edges with intensity gradient more than maxVal are sure to be edges and those below minVal are sure to be non-edges, so discarded. Those who lie between these two thresholds are classified edges or non-edges based on their connectivity. If they are connected to “sure-edge” pixels, they are considered to be part of edges. Otherwise, they are also discarded.
OpenCV
edges = cv2.Canny(image, 100, 200)
reference: Canny Edge Detection