make_binary_image | R Documentation |
This function converts a color or grayscale image to a binary image using Gaussian smoothing and a user-specified thresholding method, such as Otsu's method.
make_binary_image(img, sigma = 0, threshold_method = "otsu")
img |
An image object. This can be a color or grayscale image loaded
into R using the |
sigma |
Numeric value specifying the standard deviation for the Gaussian
blur applied to the grayscale image. Higher values result in more smoothing. |
threshold_method |
Character string specifying the thresholding method to use.
Options are |
The function first converts the input image to grayscale using the EBImage::channel()
function.
If apply_smoothing
is TRUE
, it applies a Gaussian blur to the grayscale image to reduce noise
and smooth the image using EBImage::gblur()
. The selected thresholding method
(Otsu's method or mean thresholding) is then applied to the processed image to
calculate a threshold, which is used to convert the image to a binary format where
the foreground is marked as TRUE
and the background as FALSE
.
The function includes basic error checking to ensure that the input is a valid image object.
A binary image (logical matrix) where pixels are either TRUE
(foreground) or FALSE
(background), based on the chosen thresholding method applied to the (optionally smoothed) grayscale version of the input image.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.