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

Inconsistent plot with plotRGB(..., stretch="linear") and plot(stretch()) #550

Closed
aloboa opened this issue Feb 22, 2022 · 2 comments
Closed

Comments

@aloboa
Copy link

aloboa commented Feb 22, 2022

Using
https://www.dropbox.com/s/5z1uqd019ic0j74/LC08mini.tif

I get inconsistent display with the strectch
option in plotRGB() and with stretch():

require(terra)
LC08 <- rast("LC08mini.tif")
colort=gray.colors(32,start=0,end=1,gamma=1.0)
par(mfrow=c(2,3))
plotRGB(LC08,r=5, g=5, b=5,stretch="linear")
a <- terra::stretch(LC08[[5]],minq=0.02, maxq=0.98)
plot(a,legend=FALSE,axes=FALSE,col=colort)
plotRGB(a,r=1, g=1, b=1)

v <- stats::quantile(LC08[[5]], c(0.02, 0.98), na.rm = TRUE)
temp <- (255 * (LC08[[5]] - v[1]))/(v[2] - v[1])
temp[temp < 0] <- 0
temp[temp > 255] <- 255
plotRGB(temp,r=1, g=1, b=1)
plot(temp,legend=FALSE,axes=FALSE,col=colort)
summary(LC08[[5]])

plot_zoom

What stretching options is actually using strectch="linear" ?
It looks like the problem is in stretch(), but could not find this function in the github code.

@rhijmans
Copy link
Member

Thanks; indeed this was an issue with stretch.

@aloboa
Copy link
Author

aloboa commented Mar 21, 2022

ok, thanks. I confirm it works much better now, but there is still a difference between
plotRGB(LC08,r=1, g=1, b=1,stretch="linear")
and both

a <- terra::stretch(LC08[[1]],minq=0.02, maxq=0.98)
plotRGB(a,r=1, g=1, b=1)

and

v <- stats::quantile(LC08[[5]], c(0.02, 0.98), na.rm = TRUE)
temp <- (255 * (LC08[[5]] - v[1]))/(v[2] - v[1])
temp[temp < 0] <- 0
temp[temp > 255] <- 255
plotRGB(temp,r=1, g=1, b=1)

why?

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

2 participants