Isolating flat parts Thresholding Based Segmentation Isolate parts, then characterise later Assume Robert B. Fisher School of Informatics University of Edinburgh • Dark part • Light background • Reasonably uniform illumination − > distinguishable parts Slide 1/15 Slide credit: Bob Fisher Motivating Example Given this image, how might we label pixels as object and background? Slide 2/15 Slide credit: Bob Fisher Thresholding Introduction Key technique: thresholding Assume pixel values are separable Part and typical distribution 10000 9000 8000 7000 6000 5000 4000 3000 2000 1000 0 0 50 100 150 200 250 Spread: not quite uniform illumination + part color variations + sensor noise Slide 3/15 Slide credit: Bob Fisher Slide 4/15 Slide credit: Bob Fisher Thresholding Algorithm Thresholding: central technique Thresholding Example 1 OBJECT 10000 BACKGROUND 9000 for row = 1 : height for col = 1 : width if value(row,col) < ThreshHigh % inside high bnd % & value(row,col) > ThreshLow % optional low bnd output(row,col) = 1; else output(row,col) = 0; end Slide 5/15 Slide credit: Bob Fisher 8000 7000 6000 THRESHOLD 5000 4000 3000 2000 1000 0 0 50 100 150 Histogram 200 250 Thresholded Image Slide 6/15 Slide credit: Bob Fisher Threshold Selection 1 Convolution Exploit bimodal distribution 10000 9000 General purpose image (and signal) processing function 8000 7000 6000 5000 4000 3000 Computed by a weighted sum of image data and a fixed mask 2000 1000 0 0 50 100 150 200 250 But: • Distributions broad and some overlap − > misclassified pixels Linear operator: conv(a*B,C) = a*conv(B,C) • Shadows dark so might be classified with object Used in different processes: noise removal, smoothing, feature detection, differentiation, ... • Distribution has more than 2 peaks So: smooth histogram to improve shape for selection Slide 7/15 Slide credit: Bob Fisher Slide 8/15 Slide credit: Bob Fisher Convolution in 1D N X Output(x) = Histogram Smoothing for weight(i) ∗ input(x − i) Threshold Selection i=−N 3 2.5 2 Histogram Smoothing (in findthresh.m) Convolve with a Gaussian smoothing window 1.5 1 0.5 0 Input: Gaussian Mask and Output: -0.5 -1 -1.5 -2 -50 0 50 0.5 3 filterlen = 50; % filter thefilter = gausswin(filterlen,sizeparam); % thefilter = thefilter/sum(thefilter); % unit tmp2=conv(thefilter,thehist); % makes longer % select corresponding portion offset = floor((filterlen+1)/2); tmp1=tmp2(offset:len+offset-1); 2.5 0.4 2 0.3 1.5 1 0.2 0.5 0.1 0 -0.5 0 -1 -0.1 -1.5 -0.2 -15 -10 -5 0 5 10 -2 -50 15 0 50 Derivative of Gaussian Mask and Output: 1 0.8 0.6 0.5 0.4 0.4 0.2 0.3 0 0.2 -0.2 0.1 -0.4 0 -0.6 -0.8 -0.1 -1 -50 -0.2 -15 -10 -5 0 5 10 15 0 length size=4 norm output 50 Slide 9/15 Slide credit: Bob Fisher Slide 10/15 Slide credit: Bob Fisher Threshold Selection 2 Convolved Histogram Example Assume 2 big peaks, brighter background is higher: 1. Find biggest peak (background) 0.08 8000 0.07 7000 0.06 6000 0.05 5000 0.04 4000 0.03 3000 8000 0.02 2000 7000 2. Find next biggest peak in darker direction 3. Find lowest point in trough between peaks 1 1000 0.01 0 0 5 10 15 20 25 30 35 40 45 50 0 6000 0 50 100 150 200 250 300 5000 2 4000 3000 FILTER SHAPE SMOOTHED HISTOGRAM 2000 1000 3 0 Slide 11/15 Slide credit: Bob Fisher 0 Slide 12/15 50 100 150 200 250 300 Slide credit: Bob Fisher Peak Pick Code Omit special cases for ends of array and closing ‘end’s. peak = find(tmp1 == max(tmp1)); % find largest peak % find highest peak to left xmaxl = -1; for i = 2 : peak-1 if tmp1(i-1) < tmp1(i) & tmp1(i) >= tmp1(i+1) ... & tmp1(i)>xmaxl xmaxl = tmp1(i); pkl = i; xminl = max(tmp1)+1; for i = pkl+1 : peak-1 if tmp1(i-1) > tmp1(i) & tmp1(i) <= tmp1(i+1) ... & tmp1(i)<xminl xminl = tmp1(i); thresh = i; % find deepest valley between peaks Slide 13/15 Slide credit: Bob Fisher Lecture Overview 1. Thresholding to differentiate object from a constant and simple background (not just white backgrounds: see also bluescreening or chroma keying) 2. 1D Convolution 3. Histogram smoothing & threshold selection Slide 15/15 Slide credit: Bob Fisher Slide 14/15 Slide credit: Bob Fisher
© Copyright 2026 Paperzz