Is there a way to open BSQ file format in IDL?

  • 1
    idl? please expand – Mapperz Jan 11 '11 at 15:25
  • 2
    Not sure it this will help. We'll need more info to provide a better answer. – Michael Todd Jan 11 '11 at 17:24
  • 2
    Added links for BSQ and IDL. The only decent diagram for BSQ I could find was in the Esri help, I'm not suggesting Esri software is needed though. – Kirk Kuykendall Jan 12 '11 at 15:18

Are you using IDL with ENVI, or by itself?

If you're using IDL with ENVI (by far the easiest if you have ENVI) then the standard ENVI file reading commands will work. For example:

ENVI_SELECT, fid=fid, dims=dims, pos=pos ; Shows a dialog box to allow you to select a file
image = ENVI_GET_DATA(fid=fid, dims=dims, pos=pos) ; Gets the data into an array called image

If you don't have ENVI then it is a bit harder. You can read the BSQ data by using standard IDL binary file reading commands (see http://www.msi.umn.edu/software/idl/tutorial/idl-rwd.html#Reading%20Binary%20Data but you'll need to know the dimensions of the image (samples, lines and bands) to be able to split it up sensibly. This information is often stored in a .hdr file, which ENVI reads automatically when you use the method above.


IDL reads Band Sequential (BSQ) binary file format structure as [Column,Row,Band]

BSQ, BIL and BIP are multiband encodings where:
a 8-bit Grey scale image would encode 1 band of data 
a 24-bit RGB additive color image would be 3 bands of data
a 32-bit CMYK subtractive color image would be 4 bands of data
Discrete multispectral images, or contiguous hyperspectral images
would have increasing numbers of bands.

So, as noted by @robintw you need to know the dimensions, and the source/sensor of your image. Other than the BSQ encoding, you need to know four things to read the data into an IDL interactive array. You need the Column count, the Row Count, the Band count and the Data type. Of course for any geospatial work outside IDL you would need to know the nominal pixel size and coordinates of at least 3 control points for image registration. And additional details to populate an ESRI Grid World file.

For decoding your BSQ data, IDL binary data type choices are

0   Undefined
1   Byte
2   Integer
3   Longword Integer
4   Floating point
5   Double-precision floating
6   Complex
7   String
8   Structure
9   Double-precision complex
10  Pointer
11  Object reference
12  Unsigned Integer
13  Unsigned Longword Integer
14  64-Bit Integer
15  Unsigned 64-Bit Integer

So with the minimum info at hand: To "open" the data you create a new IDL Procedure

make array of (columns,rows,bands) assign to working_array
open the bsq_image for reading
nested loops to read-in binary_values
for each band
  for each row
    for each column
      read the binary_value of type from the bsq_image
      write the data to the working_array
display working_array ;;ordered as needed for false color aesthetics
  • @Yudine, should there be an attachement or some details? – V Stuart Foote Jan 13 '11 at 18:06
  • @ Stuart, this is the file details ENVI description = { File Resize Result, x resize factor: 1.000000, y resize factor: 1.000000. [Thu Jan 13 18:15:18 2011]} samples = 338 lines = 308 bands = 125 header offset = 0 file type = ENVI Standard data type = 2 interleave = bsq sensor type = Unknown byte order = 0 x start = 459 y start = 1735 Number of bands = 125 – Yudine Jan 13 '11 at 19:54
  • @Yudine, looks like you have every thing you need to read the image into an IDL array. 338 samples --> columns, 308 lines --> rows, 125 bands. Data type 2 integer (probably 0-255). And the byte order is 0, i.e. Little Endian so direct read onto a Windows PC (would have to transform (Swap_If_Big_Endian) if a 1. So create a new Pro in the IDLDE GUI, and follow the pseudo code. A read of Michael Todd's above note with the link to a class exercise at UIdaho should help you with syntax of the code. Then your only issue will be deciding which bands in the array to display, 125 to combine. – V Stuart Foote Jan 13 '11 at 22:59

I don't have experience with either bsq or idl, but since gdal supports bsq, you could try using gdal_translate to convert your file to a geotiff. IDL seems to support reading tif files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.