0

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

dww
  • 30,425
  • 5
  • 68
  • 111
L. Holmes
  • 21
  • 2

3 Answers3

0

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.

  • Thanks a lot ! But how dose it mean: "three bands in an image it will come under a Hyperspectral image"? In my opion, .jpg or .tif is also a three-band image in this case? Or is there any other knowledge about image format I should learn... Looking forward to your reply ^_^ – L. Holmes Feb 23 '19 at 14:35
  • What I meant was using `envi.save_image` will save it as a hypercube with the band number you specify. We can save it as a normal colour image with 3 bands for (R,G,B) using differnt commands like `save_rgb`. I'm not that familiar with R, but this is with respect to sPy. – fruitspunchsamurai Feb 25 '19 at 07:02
  • I got that. I am sure it will work. However, I still want to know what's the difference between just stacking rgb bands together and `save_rgb`. It may concerns the data format stored by computer? I will try to use sPy to find out that. Thanks again! – L. Holmes Feb 28 '19 at 01:24
  • I kind of edited my answer to answer what I could ,to your query. – fruitspunchsamurai Feb 28 '19 at 10:56
  • The ```R``` function ```raster::writeRaster()``` is perfectly capable of writing a *.tif* file Windows understands. You don't have to save it as *.png* or use other programs. You just need to pass the correct options to ```writeRaster()``` (see my answer). – Manuel Popp May 28 '21 at 10:24
0

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.

Manuel Popp
  • 1,003
  • 1
  • 10
  • 33
0

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")
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63