X
4247

How to Read Images with Row or Band Offsets (Minor or Major Offsets)

Question:

If I have data that is stored with extra bytes at the beginning of each line, or the beginning of each band, how do I tell ENVI to handle those offsets properly?

Answer:

The extra bytes at the beginning of each line or each band are called frame offsets. The following table describes the locations of major and minor frame offsets within a file, as they are defined for the different types of interleaves of multi-band imagery.

Interleave

Minor Frame

Major Frame

BSQ

# of samples (line)

# of samples by # of lines (band)

BIL

# of samples (line)

# of samples by # of bands

BIP

# of bands (spectrum)

# of bands by # of samples

 

The new ENVI architecture does not have a way to handle frame offsets. If the major or minor frame offset values in the ENVI header (the ASCII *.hdr file associated with each ENVI-format image file) are populated, then ENVI will ignore those values when importing the data.

ENVI Classic does honor major and minor frame offsets.Therefore, one way to have ENVI honor the frame offset information in an ENVI header file is to do something that makes ENVI import the data using ENVI Classic. The easiest way to do this is to set the File Type field in the ENVI header to something that ENVI does not recognize. In that case, ENVI assumes that the file is some type of file format that only ENVI Classic supports, and it opens the image using ENVI Classic code. The ENVI Classic code does then honor the major and minor frame offset values in the header.

If you would like to open the image using ENVI + IDL code,then you will need to open it using ENVI Classic routines. If you want to use your code to load the data into a regular ENVI display, or use it with regular ENVI code, then you will need to wrap it as an IDLcfDataRaster, which is an old and undocumented type of raster for the ENVI API that is still available but not documented. This type of raster uses IDLcfReaderRasterEnviFid to read spatial and spectral data requests from the classic FID (File ID) used by the ENVI Classic API to identify the image. This routine works by interacting with ENVI Classic, which allows it to avoid NCOM and GDAL and other tools used for reading data in the newer ENVI architecture.

Example

The following example code will read band sequentially interleaved image data that has a file offset of 720, a minor frame offset (row offset) of 412 and a major frame offset (band offset) of 0.

*********************

pro ReadPal, fileName

 compile_opt idl2, hidden

 e = Envi()

 if (N_Elements(fileName) eq 0 || $

     ~File_Test(fileName, /READ)) then begin

   fileName = Dialog_Pickfile(TITLE='Select Input Filename', $

                               FILTER='*.1__A')

   if (fileName eq '') then begin

     return

   endif

 endif

 Envi_Setup_Head, $

   FNAME=fileName, $

   NS=1088, $

   NL=18432, $

   NB=1, $

   DATA_TYPE=6, $

   INTERLEAVE=0, $

   BYTE_ORDER=1, $

   OFFSET=720, $

   MINOR_FRAME_OFFSET=[412,0], $

   DESCRIP='Jaxa CEOS', $

   /OPEN, $

   /WRITE, $

   /NO_SYNCHRONIZE, $

   R_FID=rFid

 if(~Envi_Valid_Fid(rFid)) then begin

   Print, 'Unable to open file: ' + fileName

   return

 endif

 !null = IDLcfOpenFile(CLASSIC_FID=rFid, /PUBLIC)

End

*********************

 

created 5/2016 PS; review MM