-
Notifications
You must be signed in to change notification settings - Fork 30
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
addRasterRGB without stretching ? #26
Comments
Hi @VicenteYago and sorry foe the late reply. The issue here is a bit complicated and not immediately obvious.
In 7273013 I have now changed the default for I'd love to hear your thoughts if you think library(raster)
#> Loading required package: raster
#> Loading required package: sp
library(plainview, include.only = "poppendorf")
#> Loading required package: plainview
library(leaflet)
#> Loading required package: leaflet
library(leafem)
# supress all these proj related warnings for this example
options(warn = -1)
(max_all = max(plainview::poppendorf@data@max))
#> [1] 24972
(max_432 = max(plainview::poppendorf[[2:4]]@data@max))
#> [1] 15080
(min_432 = min(plainview::poppendorf[[2:4]]@data@min))
#> [1] 6154
# plotRGB default -> using max_all
plotRGB(plainview::poppendorf, 4, 3, 2) # addRasterRGB default -> using max_432
leaflet() %>%
addRasterRGB(
plainview::poppendorf
, 4, 3, 2
) # plotRGB -> using max_432
plotRGB(plainview::poppendorf, 4, 3, 2, scale = max_432) # addRasterRGB -> using domain = c(0, max_432)
leaflet() %>%
addRasterRGB(
plainview::poppendorf
, 4, 3, 2
, quantiles = NULL
, domain = c(0, max_432)
) # plotRGB default -> using max_all
plotRGB(plainview::poppendorf, 4, 3, 2) # addRasterRGB -> using max_all
leaflet() %>%
addRasterRGB(
plainview::poppendorf
, 4, 3, 2
, quantiles = NULL
, domain = c(0, max_all)
) Created on 2021-05-24 by the reprex package (v2.0.0) |
The default in raster::plotRGB is to not stretch (in my terminology). But it needs to know the scale of the RGB values and assumes that these are between 0 and 255, but there is some logic that checks if there are higher values. If these are found, the maximum value found is used as If you know the scale, you could provide it
If you want stretching, you can do
|
Thanks @rhijmans !
? |
The RGB channels (bands, color components) are intensities in red, green and blue, between 0 and If Now if I look at
You could argue (and it was raster did) that `n`` should be 24972, or the nearest power of 2 that is larger than that (2^14)-1; even if that band is not used as a RGB channel. I believe that in this case (Landsat data) the numbers can go up to (2^16)-1 = 65535 (unsigned 2 byte integer). But even if that were theoretically correct, it cannot be used here, as the entire image becomes black. And the layers in a Raster* object could of course come from different sources, in which case all bets are off, and it may be safer to just use the values in the R, G, B, channels; also to always have the same result if these three layers are used, no matter what larger object they may be part of. So in practice, stretching is used to avoid dull, or even entirely black, images. By default, |
Thanks again @rhijmans , I think I'm gonna stick with the current implementation to "stretch" the RGB values between min/max of the supplied layers. The user can decide to change it to e.g. c(0, max) or any other combination if they want to. But having a default that effectively shows the most possible detail is IMO desirable. |
Hi, i have the following RGB image:
The visualization its the result of this code:
Note plotRGB its not performing stretching.
And if i run this code, with default stretching:
The result is:
my question is if addRasterRGB can be used without stretching so that the result is the same as plotRGB
I tried the following without succes:
Thanks!.
The text was updated successfully, but these errors were encountered: