auto_thresh: Automatically threshold an array of non-negative integers.

Description Usage Arguments Details Value Acknowledgements References Examples

View source: R/thresh.R

Description

These functions apply the ImageJ "Auto Threshold" plugin's image thresholding methods. The available methods are "IJDefault", "Huang", "Huang2", "Intermodes", "IsoData", "Li", "MaxEntropy", "Mean", "MinErrorI", "Minimum", "Moments", "Otsu", "Percentile", "RenyiEntropy", "Shanbhag", "Triangle" and "Yen". Read about them at https://imagej.net/plugins/auto-threshold.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
auto_thresh(
  int_arr,
  method,
  ignore_black = FALSE,
  ignore_white = FALSE,
  ignore_na = FALSE
)

auto_thresh_mask(
  int_arr,
  method,
  ignore_black = FALSE,
  ignore_white = FALSE,
  ignore_na = FALSE
)

auto_thresh_apply_mask(
  int_arr,
  method,
  fail = NA,
  ignore_black = FALSE,
  ignore_white = FALSE,
  ignore_na = FALSE
)

mask(
  int_arr,
  method,
  ignore_black = FALSE,
  ignore_white = FALSE,
  ignore_na = FALSE
)

apply_mask(
  int_arr,
  method,
  fail = NA,
  ignore_black = FALSE,
  ignore_white = FALSE,
  ignore_na = FALSE
)

Arguments

int_arr

An array (or vector) of non-negative integers.

method

The name of the thresholding method you wish to use. The available methods are "IJDefault", "Huang", "Huang2", "Intermodes", "IsoData", "Li", "MaxEntropy", "Mean", "MinErrorI", "Minimum", "Moments", "Otsu", "Percentile", "RenyiEntropy", "Shanbhag", "Triangle" and "Yen". Partial matching is performed i.e. method = "h" is enough to get you "Huang" and method = "in" is enough to get you "Intermodes". To perform manual thresholding (where you set the threshold yourself), supply the threshold here as a number e.g. method = 3; so note that this would not select the third method in the above list of methods.

ignore_black

Ignore black pixels/elements (zeros) when performing the thresholding?

ignore_white

Ignore white pixels when performing the thresholding? If set to TRUE, the function makes a good guess as to what the white (saturated) value would be (see 'Details'). If this is set to a number, all pixels with value greater than or equal to that number are ignored.

ignore_na

This should be TRUE if NAs in int_arr should be ignored or FALSE if you want the presence of NAs in int_arr to throw an error.

fail

When using auto_thresh_apply_mask(), to what value do you wish to set the pixels which fail to exceed the threshold? fail = 'saturate' sets them to saturated value (see "Details"). fail = 'zero' sets them to zero. You can also specify directly here a natural number (must be between 0 and 2^16 - 1) to use.

Details

Value

auto_thresh() returns an object of class th containing the threshold value. Pixels exceeding this threshold pass the thresholding, pixels at or below this level fail.

auto_thresh_mask() returns an object of class masked_arr which is a binarized version of the input, with a value of TRUE at points which exceed the threshold and FALSE at those which do not.

auto_thresh_apply_mask() returns and object of class threshed_arr which is the original input masked by the threshold, i.e. all points not exceeding the threshold are set to a user-defined value (default NA).

mask() is the same as auto_thresh_mask() and apply_mask() is the same as auto_thresh_apply_mask().

Acknowledgements

Gabriel Landini coded all of these functions in Java. These java functions were then translated to C++.

References

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
img_location <- system.file("extdata", "eg.tif", package = "autothresholdr")
img <- ijtiff::read_tif(img_location)
auto_thresh(img, "huang")
img_value_count <- magrittr::set_names(as.data.frame(table(img)),
                                      c("value", "n"))
print(head(img_value_count))
auto_thresh(img_value_count, "Huang")
auto_thresh(img, "tri")
auto_thresh(img, "Otsu")
auto_thresh(img, 9)
mask <- auto_thresh_mask(img, "huang")
ijtiff::display(mask[, , 1, 1])
masked <- auto_thresh_apply_mask(img, "huang")
ijtiff::display(masked[, , 1, 1])
masked <- auto_thresh_apply_mask(img, 25)
ijtiff::display(masked[, , 1, 1])

autothresholdr documentation built on Jan. 4, 2022, 5:11 p.m.