CSFG
English Deutsch Beta Español Beta język polski (2.6.0)
Chapters Curriculum Guides Appendices

Computer Vision
14.4. Thresholding

Computer Vision

  • 14.1. What's the big picture?
  • 14.2. Lights, camera, action!
  • 14.3. Noise
  • 14.4. Thresholding
  • 14.5. Face recognition
  • 14.6. Edge detection
  • 14.7. Depth
  • 14.8. The whole story!
  • 14.9. Further reading

Another technique that is sometimes useful in computer vision is thresholding. This is something which is relatively simple to implement, but can be quite useful.

If you have a greyscale image, and you want to detect regions that are darker or lighter, it could be useful to simply transform any pixel above a certain level of lightness to pure white, and any other pixel to pure black. In the Data Representation chapter we talked about how pixels are all represented as sets of numbers between 0 and 255 which represent red, green and blue values. We can change a pixel to greyscale by simply taking the average of all three of these values and setting all three values to be this average.

Once we have done this, we can apply a threshold to the image to decide whether certain pixels are in certain regions. The following interactive allows you to do this to an image you upload. Try using different thresholds on different images and observing the results.

Thumbnail of Pixel Viewer interactive

Greyscale thresholding

The next interactive lets you do the same thing, but on the original colour image. You can set up more complicated statements as your threshold, such as "Red > 127 AND Green < 127 OR Blue > 63". Does applying these complex thresholds gives you more flexibility in finding specific regions of colour?

Thumbnail of Pixel Viewer interactive

Colour thresholding

Thresholding on its own isn't a very powerful tool, but it can be very useful when combined with other techniques as we shall see later.

Previous:
Noise
Next:
Face recognition

Looking for something for primary schools? Check out CS Unplugged.

The Computer Science Field Guide is an online interactive resource for high school students learning about computer science.

Useful Links

  • About
  • Chapters
  • Interactives
  • Curriculum Guides

Community

  • Twitter
  • YouTube
  • GitHub

Help

  • Search
  • Glossary
  • Feedback

Switch to teacher mode

English | Deutsch | Español | język polski (2.6.0)

The Computer Science Field Guide material is open source on GitHub, and this website's content is shared under a Creative Commons Attribution-ShareAlike 4.0 International license. The Computer Science Field Guide is a project by the Computer Science Education Research Group at the University of Canterbury, New Zealand. Icons provided generously by icons8.

3.16.0

This definition is not available in English, sorry!