Computer Vision Interview
40 Q&A
Chapter 3
Segmentation Basics — Interview Q&A
Thresholding (global, Otsu, adaptive) and morphological operations for binary masks and region cleanup.
40 questions
Chapter 3
Image Thresholding: 20 Essential Q&A
1
What is image thresholding?
⚡ easy
Answer: Classifying pixels as foreground vs background by comparing intensity to one or more thresholds—produces binary or multi-label masks.
2
What is global thresholding?
⚡ easy
Answer: Single threshold T for the whole image: pixel → foreground if I > T (or < depending on type). Fast but fails under uneven lighting or overlapping histograms.
3
When use inverse binary threshold?
⚡ easy
Answer: When objects are darker than background (or you want white objects on black mask). Complement of standard binary THRESH_BINARY.
4
How does Otsu choose T?
📊 medium
Answer: Assumes roughly bimodal histogram; picks T that minimizes intra-class variance (equivalently maximizes between-class variance). Automatic, no manual T.
_, bw = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
5
When does Otsu fail?
📊 medium
Answer: Unimodal or flat histograms, uneven illumination, low contrast, or when foreground fraction is tiny—histogram may not have clear valleys.
6
What is adaptive mean threshold?
📊 medium
Answer: For each pixel, threshold = mean of local neighborhood − C. Handles varying illumination; needs block size larger than foreground features.
7
Adaptive threshold with Gaussian weights?
📊 medium
Answer: Local threshold from Gaussian-weighted mean instead of flat mean—smoother local estimates, slightly better on gradual shading.
8
What is block size in adaptive threshold?
⚡ easy
Answer: Odd window size defining local neighborhood. Too small: noisy mask; too large: loses detail near object boundaries.
9
What is Sauvola / Niblack?
🔥 hard
Answer: Local methods using mean and standard deviation to set threshold—good for document and degraded scans with uneven background.
10
Fix uneven lighting before threshold?
⚡ easy
Answer: Homomorphic filtering, background normalization, CLAHE on luminance, or large-kernel low-pass estimate of illumination to flatten.
11
Threshold colored objects?
📊 medium
Answer: Often convert to HSV and threshold H/S/V ranges (e.g. colored ball)—more robust than RGB for hue-based objects under some lighting.
12
What is multi-level thresholding?
📊 medium
Answer: Several thresholds to get multiple classes (e.g. tissue types). Extension of Otsu exists (multi-Otsu) but cost grows with levels.
13
How pick T without Otsu?
📊 medium
Answer: Manual inspection, ROC on validation set, entropy methods, or trial with domain constraints (known object brightness).
14
Common approach for scanned documents?
⚡ easy
Answer: Adaptive threshold or Sauvola-class; deskew/denoise first; morphology to clean speckles—DL methods also used for hard cases.
15
Why binary masks have holes / noise?
⚡ easy
Answer: Sensor noise, shadows, partial overlap of histograms—use morphology, median blur pre-threshold, or adaptive methods.
16
Apply morphology after thresholding?
📊 medium
Answer: Yes—opening removes pepper noise, closing fills small holes in foreground; preserves label if structuring element smaller than features.
17
Do deep nets replace thresholding?
📊 medium
Answer: For complex scenes, semantic segmentation wins; classical thresholding remains fast for controlled lighting, industrial vision, and documents.
18
What is soft thresholding (wavelets)?
🔥 hard
Answer: Shrinks coefficients toward zero—used in denoising, not classical image binarization. Mention only if interviewer asks denoising context.
19
Threshold on float vs uint8?
⚡ easy
Answer: Same logic but ensure consistent range ([0,1] vs 0–255). Always know your image dtype before comparing to T.
20
Typical order: blur → threshold → morph?
📊 medium
Answer: Often denoise/blur lightly → threshold → morphological cleanup—order depends on whether blur destroys thin structures.
Morphological Operations: 20 Essential Q&A
21
What is mathematical morphology?
⚡ easy
Answer: Non-linear image ops based on set theory with a structuring element—shape analysis, denoising binary masks, and extracting boundaries.
22
Define erosion (binary).
📊 medium
Answer: SE fits inside foreground: output pixel on only if SE fully contained in foreground—shrinks objects, removes thin protrusions, separates touching objects if SE sized right.
23
Define dilation (binary).
📊 medium
Answer: SE hits foreground: output on if SE overlaps foreground—grows objects, fills small holes and gaps, reconnects broken strokes.
24
What is opening?
📊 medium
Answer: Erosion then dilation with same SE—removes small bright noise (pepper) and smooths boundaries without changing coarse size as much as raw erosion.
25
What is closing?
📊 medium
Answer: Dilation then erosion—fills small dark holes (salt holes in foreground), connects nearby components, smooths inward concavities.
26
What is a structuring element (SE)?
⚡ easy
Answer: Small binary mask defining neighborhood shape—disk is isotropic; rectangle aligns to axes; size controls scale of effect.
27
Disk vs square SE?
⚡ easy
Answer: Disk gives isotropic rounding; axis-aligned square can preserve Manhattan geometry—choice affects anisotropy of shrink/grow.
28
State duality between erosion and dilation.
🔥 hard
Answer: Erosion of foreground equals dilation of background complement (with reflected SE)—lets derive properties and implement efficiently.
29
Extract boundary with morphology?
📊 medium
Answer: Boundary ≈ original − eroded (or XOR variants)—gives outer contour ring depending on SE.
30
What is morphological gradient?
📊 medium
Answer: Dilation − erosion—edge strength similar to gradient magnitude on binary shapes; outer/inner gradients are variants.
31
What is white top-hat?
🔥 hard
Answer: Image − opening—extracts bright small details larger than SE removed by opening; black top-hat is closing − image for dark details.
32
What is hit-or-miss?
🔥 hard
Answer: Template matching for specific pixel configurations—detects corners, endpoints, pruned skeletons using paired SE foreground/background patterns.
33
Grayscale erosion/dilation?
📊 medium
Answer: Min/max filter over SE neighborhood—useful for texture and background estimation; different from binary set interpretation but analogous.
34
Does order of opening and closing commute?
⚡ easy
Answer: No—generally opening∘closing ≠ closing∘opening. Order matters for pipeline design.
35
Clean scanned text binary mask?
📊 medium
Answer: Opening removes speckle; closing fills letter breaks—tune SE smaller than stroke width to avoid destroying characters.
36
Larger SE effect?
⚡ easy
Answer: Removes/fills larger features; too large destroys valid structure—scale SE to minimum noise size you want removed.
37
Fill holes in binary objects?
📊 medium
Answer: Geodesic reconstruction, conditional dilation from border, or flood-fill tricks—classic interview “beyond closing” answer.
38
What is skeletonization?
📊 medium
Answer: Reduce foreground to 1-pixel-wide medial axis preserving topology—sequential morphological thinning or distance-transform methods.
39
OpenCV
morphologyEx types?
⚡ easy
Answer:
MORPH_OPEN, CLOSE, GRADIENT, TOPHAT, BLACKHAT, HITMISS—single API with MORPH_ERODE/DILATE base.
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
clean = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel)
40
Morphology vs linear convolution?
📊 medium
Answer: Morphology is min/max (nonlinear); convolution is weighted sum. Morphology preserves sharp extrema semantics for shapes.
Full tutorial chapter
Pair these interview notes with the matching CV tutorial chapter.