Why does R raster::writeRaster() generate a pic which can't be shown in Win10?

525 Views Asked by At

I read my hyperspectral (.raw) file and combine three bands to "gai_out_r" Then I output as following:

writeRaster(gai_out_r,filepath,format="GTiff")

finally I got gai_out_r.tif

But, why Win10 can't display this small tif as the pic that I output the same way from envi--save image as--tif

Two tiffs are displayed by Win10 as following:

enter image description here

3

There are 3 best solutions below

0
On

Cause of the issue:

I had a similar issue and recognised that the exported .tif files had a different bit depth than .tif images I could open. The images could not be displayed using common applications, although they were not broken and I could open them in R or QGIS. Hence, the values were coded in a way Windows would not expect.

When you type ?writeRaster() you will find that there are various options when it comes to saving a .tif (or other format) using the raster::writeRaster() function. Click on the links therein to get to the dataType {raster} help site and you'll find there are various integer types to choose from.

Solution (write a Windows-readable GeoTIFF):

I set the following options to make the resulting .tif file readable (note the datatype option):

writeRaster(raster, filename = "/path/to/your/output.tif",
            format = "GTiff", datatype = "INT1U")

Note: I realised your post is from 2 and a half years ago... Anyways, may this answer help others who encounter this problem.

0
On

You are using writeRaster to write to a GTiff (GeoTiff) format file. To write to a standard tif file you can use the tiff method. With writeRaster you could also write to a PNG instead

writeRaster(gai_out_r, "gai.png")
5
On

Default windows image viewing applications doesn't support Hyperspectral Images-since you are just reading and combining 3 bands from your .raw file, the resulting image will be a hyperspectral image.You need to have separate dedicated softwares to view hypercubes or can view it using spectral-python also.

In sPy, using envi.save_image , will save it as a ENVI type file only. To save it as an rgb image file(readable in windows OS) we need to use other methods.