### Install autothresholdr from GitHub Source: https://rorynolan.github.io/autothresholdr/index.html Use this command to install the development version of the package directly from the GitHub repository. ```R devtools::install_github("rorynolan/autothresholdr") ``` -------------------------------- ### Read and display example image with ijtiff Source: https://rorynolan.github.io/autothresholdr/articles/thresholding-images.html Reads the example image that ships with the package, prints its dimensions, and displays it. The output shows the image is 8-bit float with dimensions 130x130x1x1. ```r img <- ijtiff::read_tif(system.file("extdata", "fiji_eg.tif", package = "autothresholdr" )) #> Reading image from /home/runner/work/_temp/Library/autothresholdr/extdata/fiji_eg.tif #> Reading an 8-bit, float image with dimensions 130x130x1x1 (y,x,channel,frame) . . . dim(img) #> [1] 130 130 1 1 ijtiff::display(img) # displays first channel, first frame ``` -------------------------------- ### Install autothresholdr from CRAN Source: https://rorynolan.github.io/autothresholdr/index.html Use this command to install the stable release version of the package from CRAN. ```R install.packages("autothresholdr") ``` -------------------------------- ### Example: med_stack_thresh() with Otsu and Triangle methods Source: https://rorynolan.github.io/autothresholdr/reference/med_stack_thresh.html Example usage of med_stack_thresh() on a sample image. It reads a 50-frame TIFF, displays the first frame, applies Otsu thresholding, displays the result, then applies Triangle thresholding and displays that result. The output lines show the reading messages. ```r # \donttest{ img <- ijtiff::read_tif(system.file("extdata", "50.tif", package = "autothresholdr" )) #> Reading image from /home/runner/work/_temp/Library/autothresholdr/extdata/50.tif #> Reading an 8-bit, float image with dimensions 100x100x1x50 (y,x,channel,frame) . . . ijtiff::display(img[, , 1, 1]) img_thresh_mask <- med_stack_thresh(img, "Otsu") ijtiff::display(img_thresh_mask[, , 1, 1]) ijtiff::display(img[, , 1, 1]) img_thresh_mask <- med_stack_thresh(img, "Triangle") ijtiff::display(img_thresh_mask[, , 1, 1]) # } ``` -------------------------------- ### Example: thresholding an image stack with Otsu and Huang Source: https://rorynolan.github.io/autothresholdr/reference/mean_stack_thresh.html Example usage of mean_stack_thresh() on a sample TIFF image. It reads the image, displays the first frame, applies Otsu thresholding, displays the result, then applies Huang thresholding and displays that result. The example is wrapped in \donttest{} to avoid running during package checks. ```r # \donttest{ img <- ijtiff::read_tif(system.file("extdata", "50.tif", package = "autothresholdr" )) #> Reading image from /home/runner/work/_temp/Library/autothresholdr/extdata/50.tif #> Reading an 8-bit, float image with dimensions 100x100x1x50 (y,x,channel,frame) . . . ijtiff::display(img[, , 1, 1]) img_thresh_mask <- mean_stack_thresh(img, "Otsu") ijtiff::display(img_thresh_mask[, , 1, 1]) ijtiff::display(img[, , 1, 1]) img_thresh_mask <- mean_stack_thresh(img, "Huang") ijtiff::display(img_thresh_mask[, , 1, 1]) # } ``` -------------------------------- ### Create example vector with bimodal distribution Source: https://rorynolan.github.io/autothresholdr/articles/finding-thresholds.html Creates a numeric vector with most values above 50 and a minority below 10, used as example data for thresholding. ```r x <- c(sample.int(9, 2e5, replace = TRUE), sample(51:99, 8e5, replace = TRUE)) ``` -------------------------------- ### Apply all thresholding methods and print results Source: https://rorynolan.github.io/autothresholdr/articles/finding-thresholds.html Applies all automatic thresholding methods (except MaxEntropy and Yen) to the example vector and prints the resulting thresholds. The output shows the threshold for each method. ```r library(autothresholdr) thresh_methods <- c( "IJDefault", "Huang", "Huang2", "Intermodes", "IsoData", "Li", "Mean", "MinErrorI", "Minimum", "Moments", "Otsu", "Percentile", "RenyiEntropy", "Shanbhag", "Triangle" ) thresholds <- purrr::map_dbl(thresh_methods, ~ auto_thresh(x, .)) %>% tibble(method = thresh_methods, threshold = .) print(thresholds) #> # A tibble: 15 × 2 #> method threshold #> #> 1 IJDefault 40 #> 2 Huang 9 #> 3 Huang2 9 #> 4 Intermodes 39 #> 5 IsoData 40 #> 6 Li 25 #> 7 Mean 60 #> 8 MinErrorI 60 #> 9 Minimum 33 #> 10 Moments 56 #> 11 Otsu 9 #> 12 Percentile 68 #> 13 RenyiEntropy 70 #> 14 Shanbhag 70 #> 15 Triangle 11 ``` -------------------------------- ### Plot density of example vector Source: https://rorynolan.github.io/autothresholdr/articles/finding-thresholds.html Plots the density of the example vector to visualize the bimodal distribution. ```r library(ggplot2) library(dplyr) tibble(x = x) %>% ggplot() + aes(x) + stat_density(bw = 3) ``` -------------------------------- ### auto_thresh() with Huang method Source: https://rorynolan.github.io/autothresholdr/reference/auto_thresh.html Loads an example image and applies the Huang threshold method using auto_thresh(). The output shows the threshold value 5 and attributes indicating that black, white, and NA pixels are not ignored, with method "Huang" and class "th" "integer". ```R img_location <- system.file("extdata", "eg.tif", package = "autothresholdr") img <- ijtiff::read_tif(img_location) #> Reading image from /home/runner/work/_temp/Library/autothresholdr/extdata/eg.tif #> Reading an 8-bit, float image with dimensions 100x100x1x1 (y,x,channel,frame) . . . auto_thresh(img, "huang") #> [1] 5 #> attr(,"ignore_black") #> [1] FALSE #> attr(,"ignore_white") #> [1] FALSE #> attr(,"ignore_na") #> [1] FALSE #> attr(,"autothresh_method") #> [1] "Huang" #> attr(,"class") #> [1] "th" "integer" ``` -------------------------------- ### Create frequency table from vector Source: https://rorynolan.github.io/autothresholdr/articles/finding-thresholds.html Converts the example vector into a frequency table data frame with columns 'value' and 'n', and shows the first six rows. ```r x_freqtab <- x %>% table() %>% as.data.frame() %>% magrittr::set_names(c("value", "n")) head(x_freqtab) #> value n #> 1 1 22227 #> 2 2 22001 #> 3 3 22290 #> 4 4 22211 #> 5 5 22298 #> 6 6 22082 ``` -------------------------------- ### R function signatures for auto_thresh, auto_thresh_mask, auto_thresh_apply_mask, mask, and apply_mask Source: https://rorynolan.github.io/autothresholdr/reference/auto_thresh.html Function signatures for the five thresholding functions in the autothresholdr package. Use auto_thresh() to get the threshold value, auto_thresh_mask()/mask() to get a binarized array, and auto_thresh_apply_mask()/apply_mask() to mask the original array with a user-defined fail value. All functions accept an integer array, a method name or manual threshold number, and flags for ignoring black, white, or NA values. ```r 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 ) ``` -------------------------------- ### Load autothresholdr package Source: https://rorynolan.github.io/autothresholdr/articles/thresholding-images.html Loads the autothresholdr package before using its thresholding functions. ```r library(autothresholdr) ``` -------------------------------- ### Apply Naive Thresholding to Image Stack Source: https://rorynolan.github.io/autothresholdr/articles/thresholding-image-stacks.html Applies the Triangle thresholding method to the image stack and retrieves the chosen threshold value. ```R library(autothresholdr) naiively_threshed_img <- apply_mask(img, "tri") attr(naiively_threshed_img, "thresh") # The threshold chosen by "Triangle" is 4 #> [1] 4 #> attr(,"ignore_black") #> [1] FALSE #> attr(,"ignore_white") #> [1] FALSE #> attr(,"ignore_na") #> [1] FALSE #> attr(,"autothresh_method") #> [1] "Triangle" #> attr(,"class") #> [1] "th" "integer" ``` -------------------------------- ### auto_thresh() with Otsu method Source: https://rorynolan.github.io/autothresholdr/reference/auto_thresh.html Applies the Otsu threshold method to the image. The output shows threshold 13 and attributes with method "Otsu" and class "th" "integer". ```R auto_thresh(img, "Otsu") #> [1] 13 #> attr(,"ignore_black") #> [1] FALSE #> attr(,"ignore_white") #> [1] FALSE #> attr(,"ignore_na") #> [1] FALSE #> attr(,"autothresh_method") #> [1] "Otsu" #> attr(,"class") #> [1] "th" "integer" ``` -------------------------------- ### Use auto_thresh with Huang, Triangle, and Otsu methods Source: https://rorynolan.github.io/autothresholdr/articles/finding-thresholds.html Calls auto_thresh() with three methods: "huang", "tri" (Triangle), and "otsu". Each call returns the threshold value and attributes including the method name and class. ```r auto_thresh(x, "huang") #> [1] 9 #> attr(,"ignore_black") #> [1] FALSE #> attr(,"ignore_white") #> [1] FALSE #> attr(,"ignore_na") #> [1] FALSE #> attr(,"autothresh_method") #> [1] "Huang" #> attr(,"class") #> [1] "th" "integer" auto_thresh(x, "tri") #> [1] 11 #> attr(,"ignore_black") #> [1] FALSE #> attr(,"ignore_white") #> [1] FALSE #> attr(,"ignore_na") #> [1] FALSE #> attr(,"autothresh_method") #> [1] "Triangle" #> attr(,"class") #> [1] "th" "integer" auto_thresh(x, "otsu") #> [1] 9 #> attr(,"ignore_black") #> [1] FALSE #> attr(,"ignore_white") #> [1] FALSE #> attr(,"ignore_na") #> [1] FALSE #> attr(,"autothresh_method") #> [1] "Otsu" #> attr(,"class") #> [1] "th" "integer" ``` -------------------------------- ### Visualize Median Stack Thresholding Source: https://rorynolan.github.io/autothresholdr/articles/thresholding-image-stacks.html Displays the result of applying the Triangle threshold method based on the median intensity of the stack. ```R ijtiff::display(med_stack_thresh(img, "tri")) ``` -------------------------------- ### Visualize Mean Stack Thresholding Source: https://rorynolan.github.io/autothresholdr/articles/thresholding-image-stacks.html Displays the result of applying the Triangle threshold method based on the mean intensity of the stack. ```R ijtiff::display(mean_stack_thresh(img, "tri")) ``` -------------------------------- ### stack_threshed_img(img, thresh, fail_value, stack_thresh_method) Source: https://rorynolan.github.io/autothresholdr/reference/stack_threshed_img.html Constructor for creating an object of class stack_threshed_img. It takes a 4D or 3D array, the threshold used, the fail value, and the stack thresholding method. ```APIDOC ## stack_threshed_img(img, thresh, fail_value, stack_thresh_method) ### Description Creates an object of class `stack_threshed_img`. ### Usage ```r stack_threshed_img(img, thresh, fail_value, stack_thresh_method) ``` ### Arguments - **img** (array) - Required - A 4-dimensional array in the style of an ijtiff_img (indexed by `img[y, x, channel, frame]`) or a 3-dimensional array which is a single channel of an ijtiff_img (indexed by `img[y, x, frame]`). - **thresh** (number or th object) - Required - The threshold that was used. Either a number or an object of class th. - **fail_value** (any) - Required - The value to which elements of the array which failed the thresholding were set. - **stack_thresh_method** (character) - Required - Must be set to either `"mean"` or `"median"` to tell which stacked-thresholding method was employed. ### Value An object of class `stack_threshed_img`. ### See Also `threshed_arr`, `mean_stack_thresh()`, `med_stack_thresh()`. ``` -------------------------------- ### auto_thresh_mask() with Huang and display Source: https://rorynolan.github.io/autothresholdr/reference/auto_thresh.html Creates a mask using the Huang method and displays it with ijtiff::display(). The mask is a 4D array; the first frame is shown. ```R mask <- auto_thresh_mask(img, "huang") ijtiff::display(mask[, , 1, 1]) ``` -------------------------------- ### auto_thresh() with Triangle method Source: https://rorynolan.github.io/autothresholdr/reference/auto_thresh.html Applies the Triangle threshold method to the image. The output shows threshold 3 and attributes with method "Triangle" and class "th" "integer". ```R auto_thresh(img, "tri") #> [1] 3 #> attr(,"ignore_black") #> [1] FALSE #> attr(,"ignore_white") #> [1] FALSE #> attr(,"ignore_na") #> [1] FALSE #> attr(,"autothresh_method") #> [1] "Triangle" #> attr(,"class") #> [1] "th" "integer" ``` -------------------------------- ### auto_thresh_mask(int_arr, method, ignore_black, ignore_white, ignore_na) Source: https://rorynolan.github.io/autothresholdr/reference/auto_thresh.html Applies an ImageJ Auto Threshold method to an array of non-negative integers and returns a binarized version of the input, with TRUE at points exceeding the threshold and FALSE at those that do not. ```APIDOC ## auto_thresh_mask(int_arr, method, ignore_black, ignore_white, ignore_na) ### Description Applies an ImageJ Auto Threshold method to an array of non-negative integers and returns a binarized version of the input, with `TRUE` at points which exceed the threshold and `FALSE` at those which do not. ### Usage ```r auto_thresh_mask( int_arr, method, ignore_black = FALSE, ignore_white = FALSE, ignore_na = FALSE ) ``` ### Arguments - **int_arr** (array/vector of non-negative integers) - Required - An array (or vector) of non-negative integers. - **method** (character or numeric) - Required - The name of the thresholding method to use. Available methods: `"IJDefault"`, `"Huang"`, `"Huang2"`, `"Intermodes"`, `"IsoData"`, `"Li"`, `"MaxEntropy"`, `"Mean"`, `"MinErrorI"`, `"Minimum"`, `"Moments"`, `"Otsu"`, `"Percentile"`, `"RenyiEntropy"`, `"Shanbhag"`, `"Triangle"`, `"Yen"`. Partial matching is performed. For manual thresholding, supply a number. - **ignore_black** (logical) - Optional - If `TRUE`, ignore black pixels/elements (zeros) when performing thresholding. Default is `FALSE`. - **ignore_white** (logical or numeric) - Optional - If `TRUE`, ignore white pixels (saturated value guessed). If a number, ignore all pixels with value greater than or equal to that number. Default is `FALSE`. - **ignore_na** (logical) - Optional - If `TRUE`, ignore `NA`s in `int_arr`. If `FALSE`, presence of `NA`s throws an error. Default is `FALSE`. ### Value Returns an object of class `masked_arr` which is a binarized version of the input, with `TRUE` at points which exceed the threshold and `FALSE` at those which do not. ### Details - Values greater than or equal to the found threshold pass; values less than the threshold fail. - For `ignore_white = TRUE`, if the maximum value in the array is one of `2^8-1`, `2^12-1`, `2^16-1`, or `2^32-1`, those max values are ignored. - If all values are less than `2^8`, saturated value is `2^8 - 1`; otherwise if all values are less than `2^16`, saturated value is `2^16 - 1`; otherwise saturated value is `2^32 - 1`. ``` -------------------------------- ### auto_thresh_apply_mask(int_arr, method, fail, ignore_black, ignore_white, ignore_na) Source: https://rorynolan.github.io/autothresholdr/reference/auto_thresh.html Applies an ImageJ Auto Threshold method to an array of non-negative integers and returns the original input masked by the threshold, with all points not exceeding the threshold set to a user-defined value (default NA). ```APIDOC ## auto_thresh_apply_mask(int_arr, method, fail, ignore_black, ignore_white, ignore_na) ### Description Applies an ImageJ Auto Threshold method to an array of non-negative integers and returns the original input masked by the threshold, with all points not exceeding the threshold set to a user-defined value (default `NA`). ### Usage ```r auto_thresh_apply_mask( int_arr, method, fail = NA, ignore_black = FALSE, ignore_white = FALSE, ignore_na = FALSE ) ``` ### Arguments - **int_arr** (array/vector of non-negative integers) - Required - An array (or vector) of non-negative integers. - **method** (character or numeric) - Required - The name of the thresholding method to use. Available methods: `"IJDefault"`, `"Huang"`, `"Huang2"`, `"Intermodes"`, `"IsoData"`, `"Li"`, `"MaxEntropy"`, `"Mean"`, `"MinErrorI"`, `"Minimum"`, `"Moments"`, `"Otsu"`, `"Percentile"`, `"RenyiEntropy"`, `"Shanbhag"`, `"Triangle"`, `"Yen"`. Partial matching is performed. For manual thresholding, supply a number. - **fail** (character or numeric) - Optional - Value to set pixels which fail to exceed the threshold. `fail = 'saturate'` sets them to saturated value. `fail = 'zero'` sets them to zero. Can also specify a natural number between `0` and `2^16 - 1`. Default is `NA`. - **ignore_black** (logical) - Optional - If `TRUE`, ignore black pixels/elements (zeros) when performing thresholding. Default is `FALSE`. - **ignore_white** (logical or numeric) - Optional - If `TRUE`, ignore white pixels (saturated value guessed). If a number, ignore all pixels with value greater than or equal to that number. Default is `FALSE`. - **ignore_na** (logical) - Optional - If `TRUE`, ignore `NA`s in `int_arr`. If `FALSE`, presence of `NA`s throws an error. Default is `FALSE`. ### Value Returns an 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`). ### Details - Values greater than or equal to the found threshold pass; values less than the threshold fail. - For `ignore_white = TRUE`, if the maximum value in the array is one of `2^8-1`, `2^12-1`, `2^16-1`, or `2^32-1`, those max values are ignored. - If all values are less than `2^8`, saturated value is `2^8 - 1`; otherwise if all values are less than `2^16`, saturated value is `2^16 - 1`; otherwise saturated value is `2^32 - 1`. ``` -------------------------------- ### mean_stack_thresh() Source: https://rorynolan.github.io/autothresholdr/reference/index.html Threshold every image frame in an image stack based on their mean. ```APIDOC ## mean_stack_thresh() ### Description Threshold every image frame in an image stack based on their mean. ### Usage `mean_stack_thresh()` ``` -------------------------------- ### Auto-threshold with Triangle and display mask Source: https://rorynolan.github.io/autothresholdr/articles/thresholding-images.html Computes the Triangle threshold with auto_thresh(), prints the result (19) with attributes, then displays the mask produced by mask(). The mask is an array with TRUE for pixels exceeding the threshold. ```r auto_thresh(img, "tri") #> [1] 19 #> attr(,"ignore_black") #> [1] FALSE #> attr(,"ignore_white") #> [1] FALSE #> attr(,"ignore_na") #> [1] FALSE #> attr(,"autothresh_method") #> [1] "Triangle" #> attr(,"class") #> [1] "th" "integer" ijtiff::display(mask(img, "tri")) ``` -------------------------------- ### auto_thresh() on value-count data frame with Huang Source: https://rorynolan.github.io/autothresholdr/reference/auto_thresh.html Creates a value-count data frame from the image and applies the Huang method to it. The output shows the threshold 5 and the same attributes as the direct image call, demonstrating that auto_thresh() accepts a data frame of value counts. ```R img_value_count <- magrittr::set_names(as.data.frame(table(img)), c("value", "n")) print(head(img_value_count)) #> value n #> 1 0 875 #> 2 1 106 #> 3 2 37 #> 4 3 39 #> 5 4 23 #> 6 5 27 auto_thresh(img_value_count, "Huang") #> [1] 5 #> attr(,"ignore_black") #> [1] FALSE #> attr(,"ignore_white") #> [1] FALSE #> attr(,"ignore_na") #> [1] FALSE #> attr(,"autothresh_method") #> [1] "Huang" #> attr(,"class") #> [1] "th" "integer" ``` -------------------------------- ### mask() Source: https://rorynolan.github.io/autothresholdr/reference/index.html Creates a mask from an array. ```APIDOC ## mask() ### Description Create a mask from an array. ### Usage `mask()` ``` -------------------------------- ### auto_thresh_apply_mask() with Huang and display Source: https://rorynolan.github.io/autothresholdr/reference/auto_thresh.html Applies the Huang mask to the image and displays the masked result. The masked image is a 4D array; the first frame is shown. ```R masked <- auto_thresh_apply_mask(img, "huang") ijtiff::display(masked[, , 1, 1]) ``` -------------------------------- ### auto_thresh(int_arr, method, ignore_black, ignore_white, ignore_na) Source: https://rorynolan.github.io/autothresholdr/reference/auto_thresh.html Applies an ImageJ Auto Threshold method to an array of non-negative integers and returns the threshold value. The threshold is determined such that pixels exceeding it pass the thresholding. ```APIDOC ## auto_thresh(int_arr, method, ignore_black, ignore_white, ignore_na) ### Description Applies an ImageJ Auto Threshold method to an array of non-negative integers and returns the threshold value. Pixels exceeding this threshold pass the thresholding, pixels at or below this level fail. ### Usage ```r auto_thresh( int_arr, method, ignore_black = FALSE, ignore_white = FALSE, ignore_na = FALSE ) ``` ### Arguments - **int_arr** (array/vector of non-negative integers) - Required - An array (or vector) of non-negative integers. Can also be a data frame with columns `value` and `n`, equivalent to an integer array having `n` entries of each `value`. - **method** (character or numeric) - Required - The name of the thresholding method to use. Available methods: `"IJDefault"`, `"Huang"`, `"Huang2"`, `"Intermodes"`, `"IsoData"`, `"Li"`, `"MaxEntropy"`, `"Mean"`, `"MinErrorI"`, `"Minimum"`, `"Moments"`, `"Otsu"`, `"Percentile"`, `"RenyiEntropy"`, `"Shanbhag"`, `"Triangle"`, `"Yen"`. Partial matching is performed. For manual thresholding, supply a number (e.g., `method = 3`). - **ignore_black** (logical) - Optional - If `TRUE`, ignore black pixels/elements (zeros) when performing thresholding. Default is `FALSE`. - **ignore_white** (logical or numeric) - Optional - If `TRUE`, ignore white pixels (saturated value guessed). If a number, ignore all pixels with value greater than or equal to that number. Default is `FALSE`. - **ignore_na** (logical) - Optional - If `TRUE`, ignore `NA`s in `int_arr`. If `FALSE`, presence of `NA`s throws an error. Default is `FALSE`. ### Value Returns an object of class `th` containing the threshold value. ### Details - Values greater than or equal to the found threshold pass; values less than the threshold fail. - For `ignore_white = TRUE`, if the maximum value in the array is one of `2^8-1`, `2^12-1`, `2^16-1`, or `2^32-1`, those max values are ignored. - If all values are less than `2^8`, saturated value is `2^8 - 1`; otherwise if all values are less than `2^16`, saturated value is `2^16 - 1`; otherwise saturated value is `2^32 - 1`. - If `int_arr` is a data frame with columns `value` and `n`, `ignore_white` and `ignore_black` are irrelevant. ``` -------------------------------- ### Display manual threshold mask (img > 20) Source: https://rorynolan.github.io/autothresholdr/articles/thresholding-images.html Displays a binary mask where pixels exceed a manually chosen threshold of 20. This is used to illustrate manual thresholding before using automatic methods. ```r ijtiff::display(img[, , 1, 1] > 20) ``` -------------------------------- ### apply_mask(int_arr, method, fail, ignore_black, ignore_white, ignore_na) Source: https://rorynolan.github.io/autothresholdr/reference/auto_thresh.html Alias for auto_thresh_apply_mask. Applies an ImageJ Auto Threshold method and returns the original input masked by the threshold. ```APIDOC ## apply_mask(int_arr, method, fail, ignore_black, ignore_white, ignore_na) ### Description Alias for `auto_thresh_apply_mask()`. Applies an ImageJ Auto Threshold method to an array of non-negative integers and returns the original input masked by the threshold, with all points not exceeding the threshold set to a user-defined value (default `NA`). ### Usage ```r apply_mask( int_arr, method, fail = NA, ignore_black = FALSE, ignore_white = FALSE, ignore_na = FALSE ) ``` ### Arguments - **int_arr** (array/vector of non-negative integers) - Required - An array (or vector) of non-negative integers. - **method** (character or numeric) - Required - The name of the thresholding method to use. Available methods: `"IJDefault"`, `"Huang"`, `"Huang2"`, `"Intermodes"`, `"IsoData"`, `"Li"`, `"MaxEntropy"`, `"Mean"`, `"MinErrorI"`, `"Minimum"`, `"Moments"`, `"Otsu"`, `"Percentile"`, `"RenyiEntropy"`, `"Shanbhag"`, `"Triangle"`, `"Yen"`. Partial matching is performed. For manual thresholding, supply a number. - **fail** (character or numeric) - Optional - Value to set pixels which fail to exceed the threshold. `fail = 'saturate'` sets them to saturated value. `fail = 'zero'` sets them to zero. Can also specify a natural number between `0` and `2^16 - 1`. Default is `NA`. - **ignore_black** (logical) - Optional - If `TRUE`, ignore black pixels/elements (zeros) when performing thresholding. Default is `FALSE`. - **ignore_white** (logical or numeric) - Optional - If `TRUE`, ignore white pixels (saturated value guessed). If a number, ignore all pixels with value greater than or equal to that number. Default is `FALSE`. - **ignore_na** (logical) - Optional - If `TRUE`, ignore `NA`s in `int_arr`. If `FALSE`, presence of `NA`s throws an error. Default is `FALSE`. ### Value Returns an 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`). ### Details - Values greater than or equal to the found threshold pass; values less than the threshold fail. - For `ignore_white = TRUE`, if the maximum value in the array is one of `2^8-1`, `2^12-1`, `2^16-1`, or `2^32-1`, those max values are ignored. - If all values are less than `2^8`, saturated value is `2^8 - 1`; otherwise if all values are less than `2^16`, saturated value is `2^16 - 1`; otherwise saturated value is `2^32 - 1`. ``` -------------------------------- ### Apply Triangle mask and display result Source: https://rorynolan.github.io/autothresholdr/articles/thresholding-images.html Applies the Triangle threshold mask to the original image using apply_mask(), setting non-exceeding pixels to NA, and displays the result. In the displayed image, NA pixels appear grey. ```r ijtiff::display(apply_mask(img, "tri")) ``` -------------------------------- ### med_stack_thresh() Source: https://rorynolan.github.io/autothresholdr/reference/index.html Threshold every image frame in a stack based on their median. ```APIDOC ## med_stack_thresh() ### Description Threshold every image frame in a stack based on their median. ### Usage `med_stack_thresh()` ``` -------------------------------- ### th(thresh, ignore_black, ignore_white, ignore_na, autothresh_method) Source: https://rorynolan.github.io/autothresholdr/reference/th.html Creates an object of class 'th' representing an automatically found threshold. The object is a numeric value with attributes indicating whether black, white, or NA values were ignored and the method used. ```APIDOC ## th(thresh, ignore_black, ignore_white, ignore_na, autothresh_method) ### Description Creates an object of class `th` representing a threshold found automatically via `auto_thresh()`. The object is a numeric value with attributes describing the thresholding process. ### Usage ```r th(thresh, ignore_black, ignore_white, ignore_na, autothresh_method) ``` ### Arguments - **thresh** (scalar) - Required - The threshold value. - **ignore_black** (logical) - Required - `TRUE` if black values were ignored during thresholding, `FALSE` otherwise. - **ignore_white** (logical) - Required - `TRUE` if white values were ignored during thresholding, `FALSE` otherwise. - **ignore_na** (logical) - Required - `TRUE` if `NA` values were ignored during thresholding, `FALSE` otherwise. - **autothresh_method** (character) - Required - The name of the automatic thresholding method used. ### Value An object of class `th`. ``` -------------------------------- ### stack_threshed_img() Source: https://rorynolan.github.io/autothresholdr/reference/index.html Stack-thresholded image class. ```APIDOC ## stack_threshed_img() ### Description Stack-thresholded image class. ### Usage `stack_threshed_img()` ``` -------------------------------- ### mean_stack_thresh function signature Source: https://rorynolan.github.io/autothresholdr/reference/mean_stack_thresh.html The function signature for mean_stack_thresh(). It accepts an image array, a thresholding method (or manual threshold), and options for handling failed pixels, black, white, and NA values. ```r mean_stack_thresh( img, method, fail = NA, ignore_black = FALSE, ignore_white = FALSE, ignore_na = FALSE ) ``` -------------------------------- ### th() Source: https://rorynolan.github.io/autothresholdr/reference/index.html Automatically found threshold class. ```APIDOC ## th() ### Description Automatically found threshold class. ### Usage `th()` ``` -------------------------------- ### Read and Inspect TIFF Image Stack Source: https://rorynolan.github.io/autothresholdr/articles/thresholding-image-stacks.html Reads a TIFF image stack using ijtiff and displays its dimensions. ```R img <- ijtiff::read_tif(system.file("extdata", "50.tif", package = "autothresholdr" )) #> Reading image from /home/runner/work/_temp/Library/autothresholdr/extdata/50.tif #> Reading an 8-bit, float image with dimensions 100x100x1x50 (y,x,channel,frame) . . . dim(img) #> [1] 100 100 1 50 ``` -------------------------------- ### auto_thresh_apply_mask() with numeric threshold and display Source: https://rorynolan.github.io/autothresholdr/reference/auto_thresh.html Applies a mask using a numeric threshold of 25 and displays the masked result. The masked image is a 4D array; the first frame is shown. ```R masked <- auto_thresh_apply_mask(img, 25) ijtiff::display(masked[, , 1, 1]) ``` -------------------------------- ### auto_thresh() Source: https://rorynolan.github.io/autothresholdr/reference/index.html Automatically thresholds an array of non-negative integers. ```APIDOC ## auto_thresh() ### Description Automatically threshold an array of non-negative integers. ### Usage `auto_thresh()` ``` -------------------------------- ### auto_thresh_apply_mask() Source: https://rorynolan.github.io/autothresholdr/reference/index.html Automatically thresholds an array and applies the mask. ```APIDOC ## auto_thresh_apply_mask() ### Description Automatically threshold an array of non-negative integers and apply the mask. ### Usage `auto_thresh_apply_mask()` ``` -------------------------------- ### apply_mask() Source: https://rorynolan.github.io/autothresholdr/reference/index.html Applies a mask to an array. ```APIDOC ## apply_mask() ### Description Apply a mask to an array. ### Usage `apply_mask()` ``` -------------------------------- ### mask(int_arr, method, ignore_black, ignore_white, ignore_na) Source: https://rorynolan.github.io/autothresholdr/reference/auto_thresh.html Alias for auto_thresh_mask. Applies an ImageJ Auto Threshold method and returns a binarized version of the input. ```APIDOC ## mask(int_arr, method, ignore_black, ignore_white, ignore_na) ### Description Alias for `auto_thresh_mask()`. Applies an ImageJ Auto Threshold method to an array of non-negative integers and returns a binarized version of the input, with `TRUE` at points which exceed the threshold and `FALSE` at those which do not. ### Usage ```r mask( int_arr, method, ignore_black = FALSE, ignore_white = FALSE, ignore_na = FALSE ) ``` ### Arguments - **int_arr** (array/vector of non-negative integers) - Required - An array (or vector) of non-negative integers. - **method** (character or numeric) - Required - The name of the thresholding method to use. Available methods: `"IJDefault"`, `"Huang"`, `"Huang2"`, `"Intermodes"`, `"IsoData"`, `"Li"`, `"MaxEntropy"`, `"Mean"`, `"MinErrorI"`, `"Minimum"`, `"Moments"`, `"Otsu"`, `"Percentile"`, `"RenyiEntropy"`, `"Shanbhag"`, `"Triangle"`, `"Yen"`. Partial matching is performed. For manual thresholding, supply a number. - **ignore_black** (logical) - Optional - If `TRUE`, ignore black pixels/elements (zeros) when performing thresholding. Default is `FALSE`. - **ignore_white** (logical or numeric) - Optional - If `TRUE`, ignore white pixels (saturated value guessed). If a number, ignore all pixels with value greater than or equal to that number. Default is `FALSE`. - **ignore_na** (logical) - Optional - If `TRUE`, ignore `NA`s in `int_arr`. If `FALSE`, presence of `NA`s throws an error. Default is `FALSE`. ### Value Returns an object of class `masked_arr` which is a binarized version of the input, with `TRUE` at points which exceed the threshold and `FALSE` at those which do not. ### Details - Values greater than or equal to the found threshold pass; values less than the threshold fail. - For `ignore_white = TRUE`, if the maximum value in the array is one of `2^8-1`, `2^12-1`, `2^16-1`, or `2^32-1`, those max values are ignored. - If all values are less than `2^8`, saturated value is `2^8 - 1`; otherwise if all values are less than `2^16`, saturated value is `2^16 - 1`; otherwise saturated value is `2^32 - 1`. ``` -------------------------------- ### auto_thresh() with numeric threshold Source: https://rorynolan.github.io/autothresholdr/reference/auto_thresh.html Passes a numeric threshold value 9 directly to auto_thresh(). The output shows the threshold 9 and attributes with NA values for ignore flags and method, and class "th" "numeric". ```R auto_thresh(img, 9) #> [1] 9 #> attr(,"ignore_black") #> [1] NA #> attr(,"ignore_white") #> [1] NA #> attr(,"ignore_na") #> [1] NA #> attr(,"autothresh_method") #> [1] NA #> attr(,"class") #> [1] "th" "numeric" ``` -------------------------------- ### threshed_arr(arr, thresh) Source: https://rorynolan.github.io/autothresholdr/reference/threshed_arr.html Creates an object of class threshed_arr from a thresholded array and the threshold that was applied. ```APIDOC ## threshed_arr(arr, thresh) ### Description Creates an object of class threshed_arr from a thresholded array and the threshold that was applied. ### Usage threshed_arr(arr, thresh) ### Arguments - **arr** - The thresholded array (not the original array). - **thresh** - The threshold that was used. Either a number or an object of class th. ### Value An object of class threshed_arr. ### Details The term 'array' is used loosely here in that vectors and matrices qualify as arrays. ### See also stack_threshed_img, apply_mask(). ``` -------------------------------- ### Use auto_thresh with frequency table Source: https://rorynolan.github.io/autothresholdr/articles/finding-thresholds.html Applies auto_thresh() to a frequency table data frame with columns 'value' and 'n', demonstrating that the function accepts this format. ```r auto_thresh(x_freqtab, "huang") #> [1] 9 #> attr(,"ignore_black") #> [1] FALSE #> attr(,"ignore_white") #> [1] FALSE #> attr(,"ignore_na") #> [1] FALSE #> attr(,"autothresh_method") #> [1] "Huang" #> attr(,"class") #> [1] "th" "integer" ``` -------------------------------- ### med_stack_thresh() function signature Source: https://rorynolan.github.io/autothresholdr/reference/med_stack_thresh.html Function signature for med_stack_thresh(). It thresholds every frame in an image stack based on the median of all frames per channel. The fail argument sets the value for pixels not exceeding the threshold (default NA). ```r med_stack_thresh( img, method, fail = NA, ignore_black = FALSE, ignore_white = FALSE, ignore_na = FALSE ) ``` -------------------------------- ### masked_arr() Source: https://rorynolan.github.io/autothresholdr/reference/index.html Masked array class. ```APIDOC ## masked_arr() ### Description Masked array class. ### Usage `masked_arr()` ``` -------------------------------- ### auto_thresh_mask() Source: https://rorynolan.github.io/autothresholdr/reference/index.html Automatically thresholds an array and returns a mask. ```APIDOC ## auto_thresh_mask() ### Description Automatically threshold an array of non-negative integers and return a mask. ### Usage `auto_thresh_mask()` ``` -------------------------------- ### threshed_arr() Source: https://rorynolan.github.io/autothresholdr/reference/index.html Thresholded array class. ```APIDOC ## threshed_arr() ### Description Thresholded array class. ### Usage `threshed_arr()` ``` -------------------------------- ### Filter thresholds between 10 and 49 Source: https://rorynolan.github.io/autothresholdr/articles/finding-thresholds.html Filters the thresholds data frame to show methods that selected a threshold between 10 and 49, which are the methods that separate the two groups. ```r filter(thresholds, threshold >= 10, threshold <= 49) #> # A tibble: 6 × 2 #> method threshold #> #> 1 IJDefault 40 #> 2 Intermodes 39 #> 3 IsoData 40 #> 4 Li 25 #> 5 Minimum 33 #> 6 Triangle 11 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.