Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RGB coloring issue #330

Open
BenWalterGit opened this issue Dec 10, 2024 · 0 comments
Open

RGB coloring issue #330

BenWalterGit opened this issue Dec 10, 2024 · 0 comments

Comments

@BenWalterGit
Copy link

BenWalterGit commented Dec 10, 2024

Hi

I am currently looking for help with the following problem:

When overlaying (add_overlay) a digital elevation model for Switzerland with some colors from a raster, the result somehow shows different colors and I cannot find the issue. Below you can see the (very simple) code example, the expected colors and the rayshader coloring. Since I already invested a considerable amount of time into it and can't find it, I hoped that someone knows whether my code is wrong - which most probably is the reason - or if there is some coloring issue in the add_overlay function.

Thanks in advance for your help, highly appreciated.

Benjamin

packages:

library(terra)
library(dplyr)
library(rayshader)

get layers

setwd("...")
elevation <- rast("DHM200.asc")
crs(elevation) <- crs('+init=epsg:21781')
winner_losers_overlay <- rast("Winners_and_Losers_20241209.tif")
elevation <- terra::project(elevation, winner_losers_overlay)

prepare overlay

winner_losers_overlay[winner_losers_overlay>0] <- 3
winner_losers_overlay[winner_losers_overlay<0] <- 2
winner_losers_overlay[winner_losers_overlay==0] <- 1
coltb <- data.frame(value=c(1,2,3), col=c("#F2F2F2","#EE2C2C","#43CD80"))
has.colors(winner_losers_overlay)
coltab(winner_losers_overlay) <- coltb

create overlay with rgb colors

from <- 1:3
to <- t(col2rgb(c("#F2F2F2","#EE2C2C","#43CD80")))
colored_overlay <- subst(winner_losers_overlay, from, to, names=c("red", "green", "blue"))
colored_overlay_ar <- as.array(colored_overlay)

Convert elevation raster to matrix and plot

elmat = raster_to_matrix(elevation)

elmat %>%
sphere_shade() %>%
add_overlay(overlay=colored_overlay_ar, alphacolor="white",alphalayer = 1) %>%
plot_3d(elmat,zscale=40,zoom=0.85, asp =1.85, phi=20, theta=0,windowsize = 800)

Expected colors:
Expected colors

Result:
Rayshader colors

Files.zip

@BenWalterGit BenWalterGit changed the title RGB colors seem odd RGB coloring issue Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant