Skip to content
firepick1 (Chromebook Ubuntu) edited this page Apr 29, 2014 · 16 revisions

The FireSight wrapper for OpenCV threshold compares each pixel to a threshold value and replaces the pixel with a value determined by the threshold type.

  • type Default value is THRESH_BINARY.
  • thresh Threshold value, normally between 0 and 255. Default is OTSU, which will add the THRESH_OTSU flag to type for automatic thresholding using Otsu's method. See Example 5.
  • maxval For THRESH_BINARY and THRESH_BINARY_INV, the replacement value for the type. Default is 255, which is ideal for creating image masks for 8-bit images.
  • gray Default is true, which converts image to grayscale. If false, each channel will be thresholded, unless Otsu's method is chosen, in which the image is autoatically converted to grayscale. (FireSight only)

FireSight only:

  • gray Default value is true, which converts input image to grayscale before threshold

Stage Model

{}

Example 1: threshold Pointilism pipeline

firesight -i img/absdiff.png -p json/threshold.json -o target/threshold1-color.png -Dthresh=1 -Dgray=false

Pixel:0.5ms

The input image appears bland and simple →

However, setting a threshold of 1 reveals subtle detail →

Example 2: threshold 64 color pipeline

firesight -i img/absdiff.png -p json/threshold.json -o target/threshold64-color.png -Dthresh=64 -Dgray=false

Pixel:0.5ms

Increasing the threshold to 64 reduces the detail, but accentuates colors →

Example 3: threshold 64 grayscale pipeline

firesight -i img/absdiff.png -p json/threshold.json -o target/threshold64.png -Dthresh=64

Pixel:0.2ms

Converting to grayscale gives the expected mask →

Example 4: threshold type THRESH_BINARY_INV pipeline

firesight -i img/absdiff.png -p json/threshold.json -o target/threshold64-inv.png -Dthresh=64 -Dtype=THRESH_BINARY_INV

Pixel:0.2ms

Changing the threshold type to THRESH_BINARY_INV produces the following →

Example 5: Otsu's Method pipeline

firesight -i img/part1-0.png -p json/threshold.json -o target/threshold-otsu.png -Dthresh=OTSU

Pixel:0.7ms

Otsu's method provides automatic thresholding. As with the preceding examples, the original image is generated via absdiff and has many non-zero background pixel differences:

Using Otsu's method, we can easily calculate a foreground/background threshold. Otsu's method does take more time (compare Example 4), but may be worth the convenience.

See Also

Clone this wiki locally