mean_stack_thresh: Threshold every image frame in an image stack based on their...

Description Usage Arguments Details Value Examples

View source: R/stack_thresh.R

Description

An ijtiff_img is a 4-dimensional array indexed by img[y, x, channel, frame]. For each channel (which consists of a stack of frames), this function finds a threshold based on the sum all of the frames, uses this to create a mask and then applies this mask to every frame in the stack (so for a given pillar in the image stack, either all the pixels therein are thresholded away or all are untouched, where pillar x,y of channel ch is img[y, x, ch, ]).

Usage

1
2
3
4
5
6
7
8
mean_stack_thresh(
  img,
  method,
  fail = NA,
  ignore_black = FALSE,
  ignore_white = FALSE,
  ignore_na = FALSE
)

Arguments

img

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]).

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.8 (so note that this would not select the third method in the above list of methods). This manual threshold will then be used to threshold the sum stack to create a 2D mask and then this mask will be applied to all frames in the stack. If you want a different method for each channel, specify this parameter as a vector or list, one element per channel.

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.

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.

Details

It's called mean_stack_thresh() and not sum_stack_thresh() because its easier for people to visualize the mean of an image series than to visualize the sum, but for the sake of this procedure, both are equivalent, except for the fact that the thresholding routine invoked inside this function prefers integers, which we get by using a sum but not by using a mean.

Value

An object of class stack_threshed_img which is the thresholded image (an array in the style of an ijtiff_img). Pillars not exceeding the threshold are set to the fail value (default NA).

Examples

1
2
3
4
5
6
7
8
9
img <- ijtiff::read_tif(system.file("extdata", "50.tif",
  package = "autothresholdr"
))
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])

autothresholdr documentation built on May 12, 2021, 9:07 a.m.