# 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")
# notice patch 2 (cream) - lots of stray pixels
edit_cream_layer <- editLayer(re_fit,
layer_idx = 2,
operation = "clean",
px_size = 3)
# shrinking and growing by the same element size gives us less flexibility, so
# we can also shrink and then grow, using different px_size arguments:
edit_green_1 <- editLayer(re_fit,
layer_idx = 4,
operation = "shrink",
px_size = 2)
edit_green_2 <- editLayer(edit_green_1,
layer_idx = 4,
operation = "grow",
px_size = 3)
# we can get pleasingly mondrian about it:
new_fit <- re_fit
for (i in 1:nrow(new_fit$centers)) {
new_fit <- editLayer(new_fit,
layer_idx = i,
operation = "fill",
px_size = 5, plotting = FALSE)
}
plot(new_fit)
graphics::par(current_par)
Run the code above in your browser using DataLab