I am trying to reproduce some code from this repo:
library(magick)
#> Linking to ImageMagick 6.9.11.60
#> Enabled features: fontconfig, freetype, fftw, heic, lcms, pango, webp, x11
#> Disabled features: cairo, ghostscript, raw, rsvg
#> Using 64 threads
library(sf)
#> Linking to GEOS 3.10.2, GDAL 3.4.1, PROJ 8.2.1; sf_use_s2() is TRUE
library(tidyverse)
i <-
image_read('https://images.photowall.com/products/59143/audrey-hepburn-3.jpg?h=699&q=85') |>
image_resize("300x")
# Define some variables for this step
size <- 300
n_shades <- 16
i_processed <-
i |>
image_resize(paste0(size,"x",size,"^")) |>
image_crop(geometry = paste0(size,"x",size), gravity = "center") |>
image_convert(type = "grayscale") |>
image_quantize(max = n_shades, dither=FALSE) |>
image_flip()
i_processed
i_sf <-
i_processed |>
image_raster() |>
mutate(
col2rgb(col) |> t() |> as_tibble(),
col = scales::rescale(red, to = c(1,0))) |>
select(-green, -blue, -red) |>
stars::st_as_stars() |>
st_as_sf(as_points = FALSE, merge = TRUE) |>
st_make_valid() |>
st_set_agr("constant") |>
st_normalize()
However, in this step the function rescale
does not create the object red
.
This the obtained error:
Error in eval(cols[[col]], .data, parent.frame()) :
object 'red' not found
Created on 2024-06-21 with reprex v2.1.0