Good night, gentlemens.
I am trying to compose a RGB raster in R, but it's showing a error message:
Error in grDevices::rgb(RGB[, 1], RGB[, 2], RGB[, 3], alpha = alpha, max = scale) :
color intensity 923, not in 0:255
This is the routine:
require(raster)
library(rgdal)
band_red <- raster("banda_red.tif")
band_blue <- raster("banda_blue.tif")
band_green <- raster("banda_green.tif")
s <- stack(band_blue,band_green,band_red)
plotRGB(s, r=3, g=2, b=1)
Best regards,
This suggests that your data need to be rescaled. Can you share the range of values?
This is enough to get raster to print our ranges for each band
print(s)
otherwise to be more explicit
cellStats(s, min)
cellStats(s, max)
Since one of your values - 923 - is not something obvious, like 1 or 255 then it's not clear what the scaling should be.
If you know the maximum and 0 is the minimum then this would be enough:
plotRGB(s, scale = [max])
Generally you can update each band like this, but without knowing what the overall range of values is or what they represent this is unlikely to be sensible as we need a common from
value, not the range of values in any given band.
## danger!! we also need from = ??
setValues(band_red, scales::rescale(values(band_red), to = c(0, 255)))
Down under the hood the rgb
function expects values in 0, 1 unless you specify a maxColorValue
(that's what raster::plotRGB
is doing with max = scale
as reported in the error message.
1 Like
I don't really know what to do. I try rescale, but it doesn't work.
I don't see any clear pattern in those values, there's no way you can infer the right scaling from those. I think you'll have to go back deeper into how the data you have were intended to be used - are they landsat? Do you know the steps that went into generating them, or do you have a link to the source?
Good morning.
This imagens are from Sentinel-2. I cut an area of interest as from RGB sentinel-2 on the QGIS. After this, I exported the layers (red, green, and blue) separately.
I used this website: http://neondataskills.org/R/Multi-Band-Rasters-In-R/
Thank you.
Best regards,