RasterLayer 16-bits into a RasterLayer 8-bits

廉价感情. 提交于 2019-12-11 10:02:05

问题


I have a tried to convert a RasterLayer 16-bit into a RasterLayer 8-bit in R, but I did not have success. Any ideas ?

Thanks!


回答1:


If you want to convert your RasterLayer from 16-bit to 8-bit you need to stretch your values into the 8-bit interval (0-255 unsigned) first. Then you can save it as an 8bit image:

#sample raster
library(raster)
ras16b <- raster(x=matrix(as.integer(rnorm(180*180,1000,50)),180,180))


#convert to 0-255 using the calc. function and basic raster algebra
ras8b <- calc(ras16b, fun=function(x){((x - min(x)) * 255)/(max(x)- min(x)) + 0})

#export 8b raster
writeRaster(ras8b, '/bla/bla/ras8b.tif', datatype='INT1U')

You can find more information on how to normalize values into the 0-255 interval here



来源:https://stackoverflow.com/questions/31953180/rasterlayer-16-bits-into-a-rasterlayer-8-bits

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!