# Changeset 2112Tweet

Ignore:
Timestamp:
Dec 3, 2007, 6:48:29 PM (13 years ago)
Message:
• Started dynamic thresholding.
Location:
www/study
Files:
2 edited

Unmodified
Removed
• ## www/study/part1.html

 r2028

This is a perfect example of a situation where colour accuracy does not help achieving a better result.

help achieve a better result.

1.3. Dynamic thresholding

Dynamic thresholding consists in studying the image before selecting the threshold values. One strategy, for instance, is to choose the median pixel value. This is done simply by computing a histogram of the image.

• ## www/study/study.py

 r2098 test12y(gradient256bw, 3).save("grad1-2-3.png") test12y(gradient256bw, 5).save("grad1-2-4.png") # Output 1.3.1: 2-colour threshold, dynamic thresholding def test13x(src, n): (w, h) = src.size() dest = Image((w, h)) # Compute histogram histo = [0] * 256 for y in range(h): for x in range(w): histo[(int)(src.getGray(x, y) * 255.9999)] += 1 thresholds = [1. * (1. + i) / n for i in range(n - 1)] values = [i / (n - 1.) for i in range(n)] # Parse histogram total = 0 t = 0 for i in range(256): total += histo[i] if total > thresholds[t] * w * h: thresholds[t] = i / 255.0 t += 1 if t + 1 > n - 1: break # Compute image for y in range(h): for x in range(w): c = src.getGray(x, y) for (i, t) in enumerate(thresholds): if c < t: dest.setGray(x, y, values[i]) break else: dest.setGray(x, y, values[n - 1]) return dest if chapter(1): test13x(lenna256bw, 2).save("out1-3-1.png") test13x(gradient256bw, 2).save("grad1-3-1.png") test13x(lenna256bw, 5).save("out1-3-2.png") test13x(gradient256bw, 5).save("grad1-3-2.png") ##############################################################################
Note: See TracChangeset for help on using the changeset viewer.