class: center, middle, inverse, title-slide # Week 3: Image Thresholding ## NEUS643 ### Ted Laderas ### 2020-04-14 --- # Review of Lab Session - Any questions about lab? --- class: center, middle # Image Thresholding and Binarization --- # Learning Objectives - **Learn** about *manual* and *adaptive* thresholding on an image to *binarize* it - **Learn** about *Otsu's method* to select a threshold on an image - **Learn** about *erosion* and *dilation* to fix artefacts in a binarized image --- # Glossary - **Region of Interest** - Part of an image where you want the analysis to concentrate on - **Binarized image** - an image whose intensities have been reduced to two values: 0 and 1. - **Threshold** - a cutoff that determines which intensity values become zero and which become 1. Those values that are above the cutoff become 0, and those above become 1 - **Otsu's Method** - A automated method for deciding a threshold --- # Glossary Part 2 - **adaptive thresholding** - applying a different threshold value to different regions of the image based on local values - **erosion** - applying a minimum value filter to an image - results in reducing the border around an image - **dilation** - applying a maximum value filter to an image --- # Thresholding .pull-left[<img src="image/week3/raw_image.png">] .pull-right[<img src="image/week3/binarized.png">] ??? **Segmenting** structures in image (also known as *object detection*) requires binarized images. When we binarize, we take out all of the shades of grey in our image and make it black and white. --- <img src = "image/week3/thresholding.JPG" width = 800> ??? So how do we decide the threshold for determining what is black and what is white? --- <img src = "image/week3/manual.JPG" width = 800> ??? One way to do it is to do it manually - careful inspection of the image's histogram. --- # Manual Example .pull-left[<img src = "image/week3/manual_example.png" width = 400>] .pull-right[<img src = "image/week3/manual_example2.png" width = 400>] ??? --- # Otsu's Threshold <img src="image/week3/otsu.gif" width = 600> .footnote[By Lucas(CA) - Own work, CC BY-SA 4.0, https://commons.wikimedia.org/w/index.php?curid=67144384] ??? Otsu's method is a way of deciding a threshold based on maximizing the variability between the 0-valued pixels and the 1 valued-pixels. In this gif, we can see the variability plotted as a curve. Once we have this curve, we can find its maximum using calculus, and the maximum is our threshold. --- # Otsu's Threshold .pull-left[<img src = "image/week3/otsu-histogram.png" width = 400>] .pull-right[<img src = "image/week3/otsu_image.png" width = 400>] --- <img src="image/week3/adaptive_1.JPG" width = 800> ??? Much like filtering, we can use *neighborhoods* around a pixel to decide a threshold. This can help in situations where the illumination is uneven. This method is called *adaptive thresholding*. We need to decide the size of our neighborhood. Then we build a "local" histogram from that and apply a thresholding algorithm to that local histogram. --- <img src="image/week3/adaptive_2.JPG" width = 800> ??? Here's another neighborhood and the mini histogram In R, that neighborhood can be varied by both height and width. --- # More about adaptive thresholding http://homepages.inf.ed.ac.uk/rbf/HIPR2/adpthrsh.htm --- # Adaptive Example .pull-left[<img src = "image/week3/otsu_image.png" width = 400> Otsu's Threshold] .pull-right[<img src = "image/week3/adaptive_image.png" width = 400> Adaptive Threshold] --- # Now what? - Examine binarized images for artefacts introduced in preprocessing - Attempt to fix these artefacts - Dilation and Erosion (manual) --- <img src="image/week3/dilation.JPG" width = 800> ??? - One thing we can do to fix our images is an operation called *dilation*. - *dilation* is a maximum filter on a neighborhood. - When the filter is on the edge of an object that is black and white, it will expand the object at its edges - *dilation* can be really good at fixing "holes" in our objects --- # Dilation .pull-left[Otsu Threshold Image<img src = "image/week3/otsu_image.png" width = 400> ] .pull-right[Dilated image<img src = "image/week3/dilated_image.png" width = 400> ] --- <img src="image/week3/erosion.JPG" width = 800> ??? - The reverse operation is called *erosion*, where the object is a minimum filter - The result is that the object becomes smaller at the edges --- # Erosion .pull-left[Otsu Threshold Image<img src = "image/week3/otsu_image.png" width = 400> ] .pull-right[Eroded image<img src = "image/week3/eroded_image.png" width = 400> ] --- # Opening - *erosion* followed by *dilation* .pull-left[Otsu Threshold Image<img src = "image/week3/otsu_image.png" width = 400> ] .pull-right[Opened image<img src = "image/week3/opened_image.png" width = 400> ] --- # Closing - *dilation* followed by *erosion* .pull-left[<img src = "image/week3/otsu_image.png" width = 400> Otsu Threshold Image] .pull-right[<img src = "image/week3/closed_image.png" width = 400> Opened image] --- # Discussion In breakout rooms, compare the opened and closed images. Which operation is more appropriate? Did the operations fix issues or create them? --- # Your neighborhood's shape matters .pull-left[<img src="image/week3/art3.gif" width=400> image before opening with circular neighborhood ] .pull-right[<img src="image/week3/art3opn1.gif" width=400> image after opening with circular neighborhood ] .footnote[https://homepages.inf.ed.ac.uk/rbf/HIPR2/open.htm] --- # Lab Next time - Region of Interest - Thresholding testing - Erosion/Dilation --- # Reading: Please read these sections before the lab. - [Detection By Thresholding](https://petebankhead.gitbooks.io/imagej-intro/content/chapters/thresholding/thresholding.html) - [Binary Images](https://petebankhead.gitbooks.io/imagej-intro/content/chapters/binary/binary.html) --- # Survey Fill out the survey: https://ohsu.ca1.qualtrics.com/jfe/form/SV_e99ek34B878dGap