Formula cheatsheet

Every key formula from the course, one table per lecture. Click a heading to open the full lecture.

What is computer vision?

TopicFormulaMeaning
Spatial filtering$g = f * h$Output image = input image convolved with kernel h
CV vs related fieldsimage→image = DIP; image→description = CV; description→image = graphicsClassify a field by its input and output

Eye, image formation, colour, cameras

TopicFormulaMeaning
Retinal image size$h = 17\,\text{mm}\cdot H/D$H = object height, D = distance (15 m tree at 100 m gives 2.55 mm)
Pinhole projection$x = fX/Z,\; y = fY/Z$f = focal length, Z = depth
Thin lens$\tfrac1f=\tfrac1u+\tfrac1v$u = object distance, v = image distance
Number of colours$2^{\text{bpp}}$24 bpp gives 16,777,216 colours
Image storage$M\times N\times \text{bpp}$ bitsM rows, N columns
Contrast$C=I_{max}-I_{min}$Spread of intensities
Pixel density$\text{PPI}=\sqrt{w^2+h^2}/d$w, h in pixels; d = diagonal in inches
RGB to CMY$[C,M,Y]^T=[1,1,1]^T-[R,G,B]^T$Values normalised to [0,1]
RGB to HSI: I and S$I=\tfrac{R+G+B}{3},\; S=1-\tfrac{\min(R,G,B)}{I}$I = mean intensity; S = purity
RGB to HSI: hue$\theta=\cos^{-1}\frac{\frac12[(R-G)+(R-B)]}{[(R-G)^2+(R-B)(G-B)]^{1/2}}$; $H=\theta$ if $G\ge B$, else $360^\circ-\theta$Hue angle: R = 0°, G = 120°, B = 240°
HSI to RGB (0–120°)$B=I(1-S),\; R=I\left[1+\tfrac{S\cos H}{\cos(60^\circ-H)}\right],\; G=3I-(R+B)$Other sectors: subtract 120°/240° and rotate roles
RGB to YUV$Y=0.299R+0.587G+0.114B,\; U=0.492(B-Y),\; V=0.877(R-Y)$Y = luma; U, V = colour differences

Enhancement & smoothing filters

TopicFormulaMeaning
Image negative$s=L-1-r$L levels (256 for 8-bit)
Log transform$s=c\log(1+r)$Expands dark values, compresses bright
Gamma (power law)$s=c\,r^{\gamma}$γ < 1 brightens, γ > 1 darkens
Contrast stretching$s=\frac{r-r_{min}}{r_{max}-r_{min}}(L-1)$Maps (r_min, r_max) to (0, L−1)
Normalised histogram$p_r(r_k)=n_k/MN$n_k pixels at level k
Histogram equalisation$s_k=(L-1)\sum_{j=0}^{k}p_r(r_j)$Scaled CDF, round, remap
Correlation$g(x,y)=\sum_s\sum_t w(s,t)f(x+s,y+t)$Kernel w slid over image
Convolution$g(x,y)=\sum_s\sum_t w(s,t)f(x-s,y-t)$Correlation with kernel rotated 180°
Linearity$R(f+g)=R(f)+R(g),\ R(kf)=kR(f)$Plus shift invariance = LSI system
Box (mean) filter$w=\frac{1}{mn}\mathbf{1}$Removes noise, blurs edges
2D Gaussian$G(x,y)=\frac{1}{2\pi\sigma^2}e^{-(x^2+y^2)/2\sigma^2}$Separable; σ sets blur

Sharpening & edge basics

TopicFormulaMeaning
1st difference$\partial f/\partial x=f(x+1)-f(x)$Non-zero along ramps; thick edges
2nd difference$\partial^2 f/\partial x^2=f(x+1)+f(x-1)-2f(x)$Zero crossing at a step; double edge
Laplacian$\nabla^2f=f(x{+}1,y)+f(x{-}1,y)+f(x,y{+}1)+f(x,y{-}1)-4f(x,y)$Mask [0 1 0; 1 −4 1; 0 1 0]; 8-neighbour centre −8
Laplacian sharpening$g=f-\nabla^2f$ (centre −), $g=f+\nabla^2f$ (centre +)Add edge response back
Unsharp masking$g=f+(f-\bar f)$f̄ = blurred copy
High-boost$g=f+k(f-\bar f),\ k>1$Stronger edge emphasis
Gradient magnitude$M=\sqrt{g_x^2+g_y^2}\approx|g_x|+|g_y|$Edge strength
Gradient direction$\theta=\tan^{-1}(g_y/g_x)$Perpendicular to edge
Sobel kernels$G_x=[-1\,0\,1;-2\,0\,2;-1\,0\,1],\ G_y=[-1\,-2\,-1;0\,0\,0;1\,2\,1]$Prewitt uses 1s instead of 1,2,1
Roberts cross$G_x=[1\,0;0\,-1],\ G_y=[0\,1;-1\,0]$2×2 diagonal differences
Laplacian of Gaussian$\nabla^2G=\frac{x^2+y^2-2\sigma^2}{2\pi\sigma^6}e^{-\frac{x^2+y^2}{2\sigma^2}}$Edges at zero crossings

Edges, corners, contours

TopicFormulaMeaning
Gradient$m=\sqrt{I_x^2+I_y^2},\ \theta=\tan^{-1}(I_y/I_x)$Edge strength and direction
Harris window error$E(u,v)=\sum_W[I(x+u,y+v)-I(x,y)]^2$Large for every shift = corner
Small-motion approx$I(x+u,y+v)\approx I+I_xu+I_yv$Taylor expansion used to derive M
Structure tensor$M=\sum_W\begin{bmatrix}I_x^2&I_xI_y\\I_xI_y&I_y^2\end{bmatrix}$$E\approx[u\,v]M[u\,v]^T$
Eigenvalue casesFlat: $\lambda_1,\lambda_2\approx0$; edge: one $\gg$ other; corner: both largeHow to read M
Harris response$R=\det M-k(\operatorname{tr}M)^2$, $k=0.04$–$0.06$R < 0 edge, |R| small flat, R > 0 large corner
det and trace$\det M=\lambda_1\lambda_2,\ \operatorname{tr}M=\lambda_1+\lambda_2$No eigen-decomposition needed
Hessian detector$\det H=L_{xx}L_{yy}-L_{xy}^2$Second derivatives of smoothed image
Scale-normalised LoG$\sigma^2(L_{xx}+L_{yy})$Blob detection; radius $r\approx\sqrt2\sigma$
DoG$G(k\sigma)-G(\sigma)\approx(k-1)\sigma^2\nabla^2G$Cheap LoG approximation
Suzuki–Abe border startOuter: $f(i,j)=1,\ f(i,j-1)=0$; hole: $f(i,j)\ge1,\ f(i,j+1)=0$NBD += 1 on each new border

Local descriptors & texture

TopicFormulaMeaning
Scale space$L(x,y,\sigma)=G(x,y,\sigma)*I(x,y)$Octave doubles σ, then downsample by 2
DoG pyramid$\mathrm{DoG}_i=G_{i+1}-G_i$SIFT looks for extrema here
SIFT extrema$8+9+9=26$ neighboursMax/min in 3×3×3 neighbourhood
SIFT edge rejection$\mathrm{tr}(H)^2/\det(H)<(r+1)^2/r$, $r=10$Removes edge-like keypoints
SIFT orientation$m=\sqrt{L_x^2+L_y^2},\ \theta=\tan^{-1}(L_y/L_x)$36-bin histogram, dominant peak
SIFT descriptor$4\times4\times8=128$-D16×16 patch, 16 cells, 8 bins each
Descriptor normalisation$D'=D/\|D\|$Contrast invariance
LBP$\mathrm{LBP}_{P,R}=\sum_{p=0}^{P-1}s(g_p-g_c)2^p$s(x) = 1 if x ≥ 0; histogram of codes is the feature
Gabor filter$e^{-(x'^2+\gamma^2y'^2)/2\sigma^2}\cos(2\pi x'/\lambda+\phi)$λ wavelength, θ orientation, σ width, γ aspect, φ phase
GLCM$P(i,j)=C(i,j)/\sum C$Normalised gray-level pair counts for (d, θ)
GLCM contrast, energy$\sum(i-j)^2P(i,j)$, $\sum P(i,j)^2$Local variation; uniformity
GLCM homogeneity, correlation$\sum\frac{P}{1+|i-j|}$, $\sum\frac{(i-\mu_x)(j-\mu_y)P}{\sigma_x\sigma_y}$Pair similarity; linear dependency

Thresholding & morphology

TopicFormulaMeaning
Global threshold (BINARY)$dst=M \text{ if } src\gt T,\ \text{else } 0$T = fixed threshold, M = maxval (255); other types are INV, TRUNC, TOZERO, TOZERO_INV
TRUNC / TOZERO$dst=T\ (\text{TRUNC}) \text{ or } src\ (\text{TOZERO}) \text{ if } src\gt T$TRUNC clips values above T to T; TOZERO zeroes values at or below T
Adaptive mean threshold$T(x,y)=\text{Mean}_{nbhd}-C$Per-pixel threshold from local mean minus constant C
Adaptive Gaussian threshold$T(x,y)=\text{GaussWeightedSum}_{nbhd}-C$Like adaptive mean, nearer pixels weigh more
Otsu within-class variance$\sigma_w^2(t)=\omega_0\sigma_0^2+\omega_1\sigma_1^2$Choose t that minimises this
Otsu class stats$\omega=\frac{n_k}{N},\ \mu=\frac{\sum i\,n_i}{n_k},\ \sigma^2=\frac{\sum (i-\mu)^2 n_i}{n_k}$Weight, mean, variance of each side of the split
Otsu between-class variance$\sigma_b^2=\omega_0\omega_1(\mu_0-\mu_1)^2,\ \sigma_T^2=\sigma_w^2+\sigma_b^2$Maximising σ_b² = minimising σ_w²
Erosion$A\ominus B=\{z:B_z\subseteq A\}$SE must fit inside; shrinks objects
Dilation$A\oplus B=\{z:B_z\cap A\ne\varnothing\}$SE hits object; grows objects
Opening$A\circ B=(A\ominus B)\oplus B$Erode then dilate; removes specks and spurs
Closing$A\bullet B=(A\oplus B)\ominus B$Dilate then erode; fills holes and gaps
Boundary extraction$A-(A\ominus B)$Object minus its erosion = outline

Canny & background subtraction

TopicFormulaMeaning
Gaussian kernel$G(x,y)=\frac{1}{2\pi\sigma^2}e^{-\frac{x^2+y^2}{2\sigma^2}}$Canny step 1; 3×3 version is (1/16)[1 2 1; 2 4 2; 1 2 1]
Sobel gradients$G_x=I*S_x,\ G_y=I*S_y$S_x=[-1 0 1; -2 0 2; -1 0 1], S_y=[-1 -2 -1; 0 0 0; 1 2 1]
Gradient magnitude$M=\sqrt{G_x^2+G_y^2}$Edge strength
Gradient direction$\theta=\tan^{-1}(G_y/G_x)$Perpendicular to edge; rounded to 0/45/90/135° for NMS
Non-maximum suppression$M(x,y)=G \text{ if } G\ge G(N_1)\text{ and }G\ge G(N_2),\ \text{else } 0$N1, N2 = neighbours along gradient; thins edges to 1 px
Canny double threshold$M\gt T_H$ strong; $T_L\lt M\lt T_H$ weak; $M\lt T_L$ noneHysteresis keeps weak pixels connected to strong (T_H:T_L ≈ 2:1 to 3:1)
Background subtraction$F(x,y)=\lvert I_t(x,y)-B(x,y)\rvert$Threshold F, clean with morphology
Frame differencing$D=\lvert I_t-I_{t-1}\rvert$Fast; misses slow objects
Running average background$B_t=\alpha I_t+(1-\alpha)B_{t-1}$α = learning rate

Motion & optical flow

TopicFormulaMeaning
Brightness constancy$I(x,y,t)=I(x+\Delta x,y+\Delta y,t+\Delta t)$Moving pixel keeps its intensity
Optical flow constraint$I_xu+I_yv+I_t=0$One equation, two unknowns (aperture problem)
Normal flow$(u,v)_\perp=-\dfrac{I_t}{\|\nabla I\|^2}\nabla I$Only component along gradient observable
Lucas–Kanade solution$\begin{bmatrix}u\\v\end{bmatrix}=\begin{bmatrix}\sum I_x^2&\sum I_xI_y\\\sum I_xI_y&\sum I_y^2\end{bmatrix}^{-1}\begin{bmatrix}-\sum I_xI_t\\-\sum I_yI_t\end{bmatrix}$Same flow in window; reliable at corners
Horn–Schunck energy$E=\iint (I_xu+I_yv+I_t)^2+\lambda(|\nabla u|^2+|\nabla v|^2)$Data + smoothness; dense flow
Horn–Schunck update$u=\bar u-\dfrac{I_x(I_x\bar u+I_y\bar v+I_t)}{\lambda+I_x^2+I_y^2}$ū, v̄ = neighbour averages
Pyramid scaling$d_L=d/2^L$Coarse-to-fine for large motion

Segmentation & clustering

TopicFormulaMeaning
Single / complete / average link$\min d\;/\;\max d\;/\;\frac1{|A||B|}\sum d(a,b)$Inter-cluster distances
Background update$\mathcal B^{(n+1)}=\dfrac{w_a\mathcal F+\sum_i w_i\mathcal B^{(n-i)}}{w_c}$Foreground if $|\mathcal F-\mathcal B|>T$
K-means objective$J=\sum_j\sum_{x\in C_j}\|x-\mu_j\|^2$Assign to nearest centre, recompute means, repeat
Affinity$\mathrm{aff}(x,y)=\exp\{-\|x-y\|^2/2\sigma_d^2\}$Gaussian similarity in [0, 1]
Cut$\mathrm{Cut}(A,B)=\sum_{i\in A,j\in B}w_{ij}$Weight of severed edges
Normalised cut$\dfrac{\mathrm{Cut}(A,B)}{\mathrm{Assoc}(A,V)}+\dfrac{\mathrm{Cut}(A,B)}{\mathrm{Assoc}(B,V)}$Balanced partitions
Spectral clustering$(D-W)\mathbf y=\lambda D\mathbf y$Second-smallest eigenvector, split by sign

Discontinuities & region growing

TopicFormulaMeaning
Mask response$R=\sum_{k=1}^{9}w_kz_k,\ |R|\ge T$Point mask: 8 centre, −1 elsewhere
Gradient$\|\nabla f\|=\sqrt{G_x^2+G_y^2}\approx|G_x|+|G_y|$$\alpha=\tan^{-1}(G_y/G_x)$
Laplacian$\nabla^2f=f_{xx}+f_{yy}$Zero crossings; noise-sensitive
LoG (unnormalised)$\nabla^2G=\dfrac{x^2+y^2-2\sigma^2}{\sigma^4}e^{-\frac{x^2+y^2}{2\sigma^2}}$Mexican hat; zero crossing at $r=\sqrt2\sigma$
Thresholding$g=1$ if $f>T$ else $0$T in histogram valley
Region conditions$\cup R_i=R;\ R_i\cap R_j=\varnothing;\ P(R_i)=T;\ P(R_i\cup R_j)=F$Connected, disjoint, homogeneous
Homogeneity predicate$\max(R)-\min(R)<T$ or $\sigma<T$FALSE → split into 4 quadrants
Merge ruleMerge $R_i,R_j$ if $P(R_i\cup R_j)=\text{TRUE}$Adjacent regions only

Watershed, hierarchical clustering & Hough transform

TopicFormulaMeaning
Single link$D(A,B)=\min_{x\in A,y\in B}d(x,y)$Closest pair; chains. Slide merge heights: 2, 6, 7, 15
Complete link$D(A,B)=\max_{x\in A,y\in B}d(x,y)$Farthest pair; compact. Merge heights: 2, 7, 15, 30
Pixel distance$d(i,j)=|I_i-I_j|$n items need n − 1 merges
WatershedMinima = seeds; flood by level; pixel reached by two basins = WIntensity is height; dams = watershed lines
Hough line (m-c)$c=-x_i m+y_i$Point ↔ line in parameter space; fails for vertical lines
Hough line (ρ-θ)$\rho=x\cos\theta+y\sin\theta$Bounded space; a point becomes a sinusoid
Accumulator update$A(m,c)\leftarrow A(m,c)+1$Peaks = detected lines
Circle HT$(x_i-a)^2+(y_i-b)^2=r^2$2D A(a,b) for known r; 3D A(a,b,r) otherwise
Circle HT with gradient$a=x_i-r\cos\phi_i,\ b=y_i-r\sin\phi_i$One vote per edge point
Generalised HT$x_c=x_i+r_k^i\cos\alpha_k^i,\ y_c=y_i+r_k^i\sin\alpha_k^i$φ-table (R-table) lookup by edge direction

Hough numericals, fitting, RANSAC & snakes

TopicFormulaMeaning
Hough numerical$\rho=x\cos\theta+y\sin\theta$, $\theta\in\{0,45,90,135\}^\circ$(0,1),(1,2),(2,3): 3 votes at (135°, 0.71) → y = x + 1
Least squares error$E=\sum_{i}(y_i-mx_i-b)^2=\|Y-XB\|^2$Vertical residuals
Normal equation$B=(X^TX)^{-1}X^TY$$m=\frac{n\sum xy-\sum x\sum y}{n\sum x^2-(\sum x)^2}$
Total least squares$E=\sum_i(ax_i+by_i-d)^2,\ a^2+b^2=1$Perpendicular distance; handles vertical lines
Robust estimator$\rho(u;\sigma)=\dfrac{u^2}{\sigma^2+u^2}$Saturates at 1 for outliers
RANSAC threshold$t^2=3.84\,\sigma^2$95% of inliers inside t
RANSAC iterations$N=\dfrac{\log(1-p)}{\log\!\big(1-(1-e)^s\big)}$p confidence, e outlier ratio, s sample size; round up
RANSAC minimal setsline 2, translation 1, affine 3, homography 4, F 8 (7)Smallest sample defining the model
Snake energy$\mathcal E=\int(\alpha E_{cont}+\beta E_{curv}+\gamma E_{img})ds$Minimise over contour
Snake continuity$E_{cont}=\|p_i-p_{i-1}\|^2$Keeps points close
Snake curvature$E_{curv}=\|p_{i+1}-2p_i+p_{i-1}\|^2$Penalises bending
Snake image term$E_{img}=-\|\nabla I\|$Pulls contour onto edges

Epipolar geometry & stereo

TopicFormulaMeaning
Depth from disparity$Z=\dfrac{fB}{d},\ d=x_L-x_R$f focal length (px), B baseline; near = large d
3D back-projection$X=\frac{(x-c_x)Z}{f_x},\ Y=\frac{(y-c_y)Z}{f_y}$Pixel + depth to world coordinates
Essential matrix$x_R^TEx_L=0,\ E=[\mathbf t]_\times R$Normalised coords; rank 2, 5 DOF
Skew matrix$[\mathbf t]_\times=\begin{pmatrix}0&-t_z&t_y\\t_z&0&-t_x\\-t_y&t_x&0\end{pmatrix}$Cross product as a matrix
Fundamental matrix$p_R^TFp_L=0,\ F=K_R^{-T}EK_L^{-1}$Pixel coords; rank 2, 7 DOF
Epipolar lines$\mathbf l_R=Fp_L,\ \mathbf l_L=F^Tp_R$Match must lie on this line
Epipoles$Fe_L=0,\ F^Te_R=0$Null vectors of F and Fᵀ
8-point row$[x'x,\ x'y,\ x',\ y'x,\ y'y,\ y',\ x,\ y,\ 1]\,\mathbf f=0$Solve Af = 0 by SVD, then force rank 2
Normalised 8-point$F=T'^TF_nT$Centroid 0, mean distance √2, then denormalise
7-point$F=\alpha F_1+(1-\alpha)F_2,\ \det F=0$Cubic in α, up to 3 solutions
Window matching$SAD=\sum|I_L(x{+}u,y{+}v)-I_R(x{+}u{-}d,y{+}v)|$Pick d with smallest cost; SSD squares

Invariant features & image alignment

TopicFormulaMeaning
Euclidean distance$d(D_1,D_2)=\sqrt{\sum_i(D_{1i}-D_{2i})^2}$Float descriptors (SIFT)
Ratio test$r=d_1/d_2$, accept if $r\lt0.8$Reject ambiguous matches
SSD / SAD$\sum(H-F)^2,\ \sum|H-F|$Lower = more similar
NCC$\dfrac{\sum(H-\bar H)(F-\bar F)}{\sqrt{\sum(H-\bar H)^2}\sqrt{\sum(F-\bar F)^2}}$In [−1, 1], higher better; brightness-robust
Hamming distance$d_H=\sum_i D_1(i)\oplus D_2(i)$Binary descriptors (ORB, BRIEF)
Rotation$\begin{bmatrix}\cos\theta&-\sin\theta\\\sin\theta&\cos\theta\end{bmatrix}$1 DOF
Translation (homogeneous)$\begin{bmatrix}1&0&t_x\\0&1&t_y\\0&0&1\end{bmatrix}$Needs homogeneous coords
Composition$T=T_2T_1$T₁ applied first; order matters
Affine (6 DOF)$\begin{bmatrix}a&b&t_x\\c&d&t_y\\0&0&1\end{bmatrix}$Parallel lines stay parallel; 3 point pairs
Homography (8 DOF)$\mathbf x'\sim H\mathbf x,\ h_{33}=1$Divide by w′; needs 4 point pairs

Recognition & high-level vision

TopicFormulaMeaning
Entropy (active learning)$H=-\sum_i p_i\log p_i$Higher = more uncertain, so label that sample
Margin sampling$p_{(1)}-p_{(2)}$Small margin = high uncertainty
Box format conversion$x_{max}=x+w,\ y_{max}=y+h$[x, y, w, h] to corner format
Image input size$H\times W\times C$224×224×3 = 150,528 values

Classifiers, sequence models, CNNs

TopicFormulaMeaning
Euclidean distance (KNN)$d=\sqrt{\sum_j (q_j-p_j)^2}$Take K nearest, majority vote
SVM decision rule$f(x)=w^Tx+b,\ \hat y=\text{sign}(f(x))$w normal to hyperplane, b bias
SVM margin$\text{margin}=\dfrac{2}{\lVert w\rVert}$Maximise it
Distance to hyperplane$\dfrac{|w^Tx+b|}{\lVert w\rVert}$Point to decision boundary
Artificial neuron$a=f\big(\sum_j w_jx_j+b\big)$Weighted sum + bias through activation
ReLU / sigmoid$\max(0,x),\ \dfrac1{1+e^{-x}}$Ranges [0, ∞) and (0, 1)
Gradient descent$w\leftarrow w-\eta\,\partial L/\partial w$η = learning rate
HMM joint probability$P(X,S)=\pi_{s_1}B_{s_1}(x_1)\prod_{t\ge2}A_{s_{t-1}s_t}B_{s_t}(x_t)$π initial, A transition, B emission
HMM forward step$\alpha_{t+1}(j)=\big[\sum_i\alpha_t(i)A_{ij}\big]B_j(x_{t+1})$Viterbi replaces sum with max
Conv output size$O=\Big\lfloor\dfrac{N+2P-F}{S}\Big\rfloor+1$N input, F kernel, P padding, S stride
Conv layer parameters$(F\cdot F\cdot C_{in}+1)\cdot K$K filters; pooling has 0 params
FC layer parameters$n_{in}\cdot n_{out}+n_{out}$Weights + biases

Object detection

TopicFormulaMeaning
IoU$\text{IoU}=\dfrac{A_I}{A_P+A_G-A_I}$Slide example: 16/56 ≈ 0.286
Intersection box$x_l=\max(x_1,x_1'),\ x_r=\min(x_2,x_2')$ (same for y)$A_I=\max(0,x_r-x_l)\max(0,y_b-y_t)$
Precision$\dfrac{TP}{TP+FP}$Fraction of detections correct
Recall$\dfrac{TP}{TP+FN}$Fraction of objects found
AP and mAP$AP=\int P\,dR,\ \text{mAP}=\frac1C\sum_c AP_c$Area under PR curve, averaged over classes
NMS ruleKeep top score; drop boxes with $\text{IoU}>T$Typically T = 0.5
YOLO output size$S\times S\times(5B+C)$e.g. 7×7×30
Detection loss$L=L_{cls}+\lambda L_{loc}$Classification + localisation