Free course · Lesson 3 of 5
Basic Image Processing
In this lesson you will
- Explain thresholding and histograms
- Clean up an unevenly lit document photo
Image processing changes pixel values to make information easier to see or measure. A histogram counts how many pixels have each brightness, showing whether an image is too dark or has low contrast. Thresholding turns a grayscale image into black and white.
- Global threshold: one cut-off for the whole image. Otsu's method chooses it automatically.
- Adaptive threshold: a cut-off for each neighbourhood, so documents photographed in uneven light still give clean black text.
- Morphology: erosion and dilation remove specks and fill gaps in black-and-white masks, which helps when counting seeds or grains.
Python
import cv2 page = cv2.imread("fictional_form.jpg", cv2.IMREAD_GRAYSCALE)page = cv2.GaussianBlur(page, (5, 5), 0) # reduce noise first clean = cv2.adaptiveThreshold(page, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 31, 10)cv2.imwrite("form_clean.png", clean) # PNG: lossless for documents
Practice exercise
Photograph a printed page in uneven light and describe which parts a single threshold would turn black or white wrongly.
Key takeaways
- Histograms show brightness and contrast
- Adaptive thresholding handles uneven lighting
Free self-study lesson — no certificate. For the full instructor-led program, see registration options.