Skip to content
Snippets Groups Projects
Commit b4f8282f authored by Gilquin's avatar Gilquin
Browse files

fix: correct import

feat: add input
parent 3e0ea80f
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,10 @@
import::here("dplyr", c("mutate", "sample_n"), .character_only = TRUE)
import::here(
"imager",
c("grayscale", "HSVtoRGB", "imappend", "imsplit", "map_il", "RGBtoHSV"),
c(
"as.cimg", "grayscale", "HSVtoRGB", "imappend", "imsplit",
"map_il", "RGBtoHSV"
),
.character_only = TRUE
)
import::here("magrittr", "%>%", .character_only = TRUE)
......@@ -126,10 +129,11 @@ invert_grayscale <- function(img) {
#'
#' @param img an imager::cimg
#' @param quantile a real, the quantile level used for thresholding.
#' @param G an integer, the number of mixture components.
#' @param ... mclust::densityMclust parameters
#'
#' @returns an imager::cimg
binarize <- function(img, quantile = 0.95, ...) {
binarize <- function(img, quantile = 0.95, G = 1L, ...) {
# convert to grayscale if needed and invert
if (rev(dim(img))[1L] > 1L) {
stop("A grayscale image is expected.")
......@@ -137,7 +141,7 @@ binarize <- function(img, quantile = 0.95, ...) {
# sample
sample <- sample_histogram(img)
# fit Gaussian mixture
gm <- densityMclust(sample, G = 1L, plot = FALSE, ...)
gm <- densityMclust(sample, G = G, plot = FALSE, ...)
# threshold based on 95% quantile
threshold <- qnorm(
quantile, gm$parameters$mean[1L], sqrt(gm$parameters$variance$sigmasq[1L])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment