Dithering issues.

This commit is contained in:
ryantimpe
2020-04-01 09:37:28 -04:00
parent 6a12dd4adc
commit eb51469404
3 changed files with 6 additions and 16 deletions

View File

@@ -255,12 +255,14 @@ convert_color_to_brick_dithering <- function(img_object, color_table, brick_tabl
from_space='rgb', to_space = 'rgb', method=method)
#Assign LEGO color for this cell
if(!is.character(brick_table$hex[which.min(dstncs)])){next}
mosaic_base[mosaic_base$x == xx & mosaic_base$y == yy, c("Lego_name", "Lego_color")] <-
brick_table[which.min(dstncs), c("Color", "hex")]
as.character(brick_table[which.min(dstncs), c("Color", "hex")][1,])
#Difference in color
dith_diff <- mosaic_base[mosaic_base$x == xx & mosaic_base$y == yy, c("R", "G", "B")] -
brick_table[which.min(dstncs), c("R_lego", "G_lego", "B_lego")]
as.numeric(brick_table[which.min(dstncs), c("R_lego", "G_lego", "B_lego")][1,])
# dith_diff <- dith_diff*c(0.299, 0.587, 0.114)

View File

@@ -74,7 +74,7 @@ expand.grid(
x = 1:4,
y = 1:2,
z = 1,
Color = "Bright red"
Color = "Bright red", stringsAsFactors = FALSE
) %>%
bricks_from_coords() %>%
build_bricks()
@@ -90,7 +90,7 @@ expand.grid(
x = 1:4,
y = 1:2,
z = 1,
Color = "Bright red"
Color = "Bright red", stringsAsFactors = FALSE
) %>%
dplyr::mutate(piece_type = "p") %>%
bricks_from_coords() %>%

View File

@@ -121,18 +121,6 @@ gridExtra::grid.arrange(grobs = mosaics_by_method, layout_matrix =rbind(c(1,2),c
When rendering a mosaic from a photographic with many shades of similar colors, using [dithering](https://en.wikipedia.org/wiki/Floyd%E2%80%93Steinberg_dithering) by setting `dithering = TRUE` will help to add texture to the mosaic and avoid large areas of the same color. This works particularly well for large mosaics, but is purely a stylist preference.
```{r c_dither, fig.width=6, fig.height=4}
gg_img = tempfile()
download.file("http://ryantimpe.com/files/goldengirls.JPG", gg_img, mode="wb")
c(FALSE, TRUE) %>%
purrr::map(~jpeg::readJPEG(gg_img) %>%
image_to_mosaic(dithering = .x) %>%
build_mosaic(title = paste("dithering =", .x))) -> mosaics_by_dither
gridExtra::grid.arrange(grobs = mosaics_by_dither, layout_matrix = matrix(c(1,2), ncol=2))
```
### Other color options
The input `brightness` can be used to scale up or down the RGB values of the image before color matching. The default is 1.