mirror of
https://github.com/ryantimpe/brickr.git
synced 2026-02-19 21:29:33 -06:00
Dithering issues.
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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() %>%
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user