Thresholdimage

From Eigenvector Research Documentation Wiki
Revision as of 11:26, 8 March 2012 by imported>Donal (→‎Description)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Purpose

Threshold image and return binary mask.

Synopsis

xbinary = thresholdimage(imgdso,thresholdvalue,thresholdslab,reversemask)
[xbinary,thresholdvalue] = thresholdimage(imgdso,thresholdvalue,thresholdslab,reversemask);

Description

THRESHOLDIMAGE creates a binary array from a specified slab of an image dataset. If a specific thresholdslab is not specified then the mean over all of the image slabs (after they have been normalized to range from 0 to 255) is used. The binary array values are set as:

xbinary = x > thresholdvalue

Values equal to or below threshold are set to 0, else 1.

If reversemask is set to 1 then the reverse is used:

xbinary = x <= thresholdvalue

Values equal to or below threshold are set to 1, else 0.

If the input thresholdvalue is empty then a threshold value is calculated using the ImageJ "Convert to Mask" auto thershold method. This threshold value calculation method is described as "Returns a pixel value (threshold) that can be used to divide the image into objects and background. It does this by taking a test threshold and computing the average of the pixels at or below the threshold and pixels above. It then computes the average of those two, increments the threshold, and repeats the process. Incrementing stops when the threshold is larger than the composite average. That is, threshold = (average background + average objects)/2. This description was posted to the ImageJ mailing list by Jordan Bevic.". See http://imagej.nih.gov/ij/developer/api/ij/process/ImageProcessor.html

Inputs

  • imgdso = NxMxSlices Image DataSet,
  • thresholdvalue = Threshold value,
  • thresholdslab = Single slab to use, otherwise mean of image is used,
  • reversemask = Whether to reverse the mask.

Outputs

  • xbinary = NxMxSlices logical array with values = 1 where x exceeds the threshold, otherwise 0, if option reversemask equals 0.

Example

Apply thresholdimage to the 'Swedish knackerbrod' image dataset's fifth slab. This returns a logical array with value = 1 where the bread's fifth slab value is greater than the threshold value.

load('smbread')
[xbinary,thresholdvalue] = thresholdimage(bread,[], 5, 0);  % auto-select threshold value (=42).
plotgui(buildimage(xbinary))
[xbinary,thresholdvalue] = thresholdimage(bread, 60, 5, 0); % specify threshold value = 60
plotgui(buildimage(xbinary))

See Also

morph_img, spatial_filter