# load image and recolorize it
img <- system.file("extdata/corbetti.png", package = "recolorize")
# first do a standard color binning
init_fit <- recolorize(img, bins = 2, plotting = FALSE)
# then cluster patches by similarity
re_fit <- recluster(init_fit, cutoff = 40)
# to reset graphical parameters:
current_par <- graphics::par(no.readonly = TRUE)
# examine individual layers:
layout(matrix(1:6, nrow = 2))
layers <- splitByColor(re_fit, plot_method = "color")
# we can clean them all using the same parameters...
edited_fit <- editLayers(re_fit, layer_idx = "all",
operations = "clean",
px_sizes = 2, plotting = TRUE)
# ...but some of those patches don't look so good
# we can use different px_sizes for each layer:
edited_fit_2 <- editLayers(re_fit, layer_idx = "all",
operations = "clean",
px_sizes = c(1, 3, 1,
2, 1, 2),
plotting = TRUE)
# better yet, we can fill some layers and clean others:
edited_fit_3 <- editLayers(re_fit, layer_idx = "all",
operations = c("fill", "clean",
"fill", "fill",
"fill", "clean"),
px_sizes = c(2, 3,
2, 2,
4, 2))
# or you could just get weird:
edited_fit_3 <- editLayers(re_fit, layer_idx = c(1:6),
operations = c("fill", "clean"),
px_sizes = c(10, 20))
# reset graphical parameters:
graphics::par(current_par)
Run the code above in your browser using DataLab