Monday, December 9, 2019

Thresholding - Segmentation by regions



The simplest method for partitioning an image into two regions: (i) the objects of interest and (ii) the background is the Thresholding.


1. Definition


The segmentation by thresholding consists of splitting the image in two regions depending of the pixel intensities. The algorithm can be summarized as follows (in pseudo-code):

foreach pixel do
  if pixel > threshold then
    output_pixel = 255
  else
    output_pixel = 0 
  endif

Note: We assume that the input image is a 8-bit gray-level image

2. Example


Let's start with an example. Load the `Leaf` sample image — File > Open Samples > Leaf —, then convert it in 8-bit (Image > Type > 8-bit).

Or, run this small JavaScript code:


// Load `Leaf` Sample Image
let imp = IJ.openImage("http://wsr.imagej.net/images/leaf.jpg");
// Convert in 8-bit
IJ.run(imp, "8-bit", "");

Then, we want to threshold our image with a value of 125. In ImageJ, we can do that with Process > Math > Macro... or adding the following line to the JS script:

IJ.run(imp, "Macro...", "code=v=(v>125)*255");
Note: The code (v>125)*255 works because the comparison (v>125)  — returning a boolean: true or false — is followed by a multiplication. Thus it is automatically converted into a number 1 (if true) and 0 (if false).

The resulting image is composed of two regions (Fig.1):
  1. the Objects of Interest — or Regions of Interest (ROI) in ImageJ vocabulary — in black (value = 0)
  2. the Background ( value = 255)
Fig.1: `Leaf`sample after thresholding. The Objects of Interest are in black and the background in white.

3. Using ImageJ Tool

TODO

<<  TOC : PreviousNext: Histogram >>

4. Other crazybiocomputing posts

Further readings are available in ...
  • Segmentation Series  [Link]
  • Image Processing TOC [Link]

No comments:

Post a Comment