Classical Image Processing
Classical image processing uses fixed operations such as convolution, thresholding, morphology, and geometric transforms. It is not obsolete: it is often the most auditable part of an OCR pipeline, a preprocessing step before feature extraction, or a sanity baseline for semantic segmentation.
Convolution and gradient filters
For a grayscale image and kernel , 2D convolution computes
The Sobel operator estimates horizontal and vertical derivatives with small kernels, for example
Edges become large responses because neighboring intensities differ strongly; flat regions cancel out.
Worked example
This snippet applies a Sobel-style horizontal edge filter to a toy image and reports the gradient response and maximum edge magnitude.
import numpy as np
from scipy.signal import convolve2d
img = np.zeros((5, 5)); img[:, 3:] = 10
sobel_x = np.array([[-1,0,1],[-2,0,2],[-1,0,1]])
gx = convolve2d(img, sobel_x, mode="same", boundary="symm")
print("image")
print(img.astype(int))
print("sobel_x")
print(gx.astype(int))
print("max_abs_gradient", int(np.abs(gx).max()))Observed output:
image
[[ 0 0 0 10 10]
[ 0 0 0 10 10]
[ 0 0 0 10 10]
[ 0 0 0 10 10]
[ 0 0 0 10 10]]
sobel_x
[[ 0 0 -40 -40 0]
[ 0 0 -40 -40 0]
[ 0 0 -40 -40 0]
[ 0 0 -40 -40 0]
[ 0 0 -40 -40 0]]
max_abs_gradient 40Only the vertical intensity jump produces a strong derivative. The same array contract depends on correct image representation: channel order, dtype, and padding convention all change the result.
Caveats
Fixed thresholds break under lighting changes, blur, and sensor shifts. Morphology can remove the small structures that medical image analysis cares about. Classical steps should be versioned and benchmarked like learned models, not treated as harmless preprocessing.
References
Nav