make_binary_image.Rd
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")
An image object. This can be a color or grayscale image loaded
into R using the EBImage
package.
Numeric value specifying the standard deviation for the Gaussian
blur applied to the grayscale image. Higher values result in more smoothing. 0
skips
smoothing. Default is 0
.
Character string specifying the thresholding method to use.
Options are "otsu"
for Otsu's method or "mean"
for mean thresholding. Default is "otsu"
.
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.
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.