X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 05 Jul 2010 07:38 AM by  anon
write tiff from hdf band
 2 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
05 Jul 2010 07:38 AM
    Hello IDL Community, I tried to write an IDL routine which consecutively opens bands of a hdf file and writes each of them to a tiff file, but the result looks quite speckled (in comparison to a manual save in ENVI). So far, I cannot figure out the error; consulted the IDL help for different hdf procedures and functions without success (perhaps missed somthing important, I don't know - it is the first time of working with hdf file). The hdf file includes several VI bands (data type integer), the tiff has to be 8-bit grayscale. *it would also be helpful, if someone has a tip how to put the hdf bands into an ENVI layerstack (BSQ or BIL) as the tiff "problem" can't be fixed. Here my code, exclusive loop and some naming convention for the output file: input = 'input.hdf' out = 'out.tiff' SDinterface_id = HDF_SD_START(input) ;bandnumber includes the loop variable SDdataset_id = HDF_SD_SELECT(SDinterface_id, bandnumber) HDF_SD_GETDATA, SDdataset_id, NDVI ;write tiff output write_tiff, out, NDVI, bits_per_sample = 8 HDF_SD_ENDACCESS, SDdataset_id HDF_SD_END, SDinterface_id Do you have an advise? I don't make any progress Thanks in advances. Best regards! Anke

    Deleted User



    New Member


    Posts:
    New Member


    --
    12 Dec 2015 06:38 AM
    Did you ever resolve this? If so, could you share your code?

    Zachary Norman



    Basic Member


    Posts:173
    Basic Member


    --
    14 Dec 2015 10:25 AM
    Hi, My guess is that the call to WRITE_TIFF is bad. I bring this up because by default I think the written data type for WRITE_TIFF is byte data which means that your speckles probably come from your data being a 16 bit or 32 bit integer. To illustrate how to correctly write a TIFF image, I included a sample program below. The first procedure is used to generate a. HDF5 data file, the second procedure is used to convert it to a TIFF. This code will only work if you have ENVI installed because it uses ENVI to extract raster data from a sample image that is included with the installation. To run the program just save all of the code below as hdf5_to_tiff.pro then compile and run. Once completed, an HDF5 file and TIFF file will be generated in the same directory that the code is saved to. ;========================================================================== ;beginning of code ;========================================================================== pro make_hdf5_file compile_opt idl2 ;get current directorya nd specify output file thisdir = FILE_DIRNAME(((SCOPE_TRACEBACK(/STRUCT))[-1]).FILENAME) outfile = thisdir + path_sep() + 'h5_out.h5' ;delete output file if it exists if file_test(outfile) then FILE_DELETE, outfile, /QUIET e = envi(/headless) ;open sample data to write to HDF5 file file = FILEPATH('qb_boulder_msi', ROOT_DIR=e.ROOT_DIR, $ SUBDIRECTORY = ['data']) raster = e.openraster(file) raster_data = raster.getdata() raster_dims = size(raster_data, /DIMENSIONS) ;[n, m, 4] for dimensions ; create HDF5 file fid = H5F_CREATE(outfile) ;create bands of data in the HDF5 file datatype_id = H5T_IDL_CREATE(raster_data) dataspace_id = H5S_CREATE_SIMPLE(raster_dims) dataset_id = H5D_CREATE(fid,'qb_boulder_msi',datatype_id,dataspace_id) ; write the raster_data to the dataset H5D_WRITE,dataset_id,raster_data ; close the identifiers H5S_CLOSE,dataspace_id H5T_CLOSE,datatype_id H5F_CLOSE,fid ;close ENVI e.close end pro hdf5_to_tiff compile_opt idl2 ;get current directorya nd specify output file thisdir = FILE_DIRNAME(((SCOPE_TRACEBACK(/STRUCT))[-1]).FILENAME) infile = thisdir + path_sep() + 'h5_out.h5' outfile = thisdir + path_sep() + 'h5_out.tif' ;read image data img_data = H5_GETDATA(infile, '/qb_boulder_msi') ;because our data is unsigned integers (16 bit) we need /SHORT keyword set write_tiff, outfile, img_data, PLANARCONFIG = 2, /SHORT end ;main level program compile_opt idl2 make_hdf5_file hdf5_to_tiff end ;========================================================================== ;end of code ;==========================================================================
    You are not authorized to post a reply.