Read IW SLC files into Matlab?

Are there any readers for IW SLC files into Matlab? Using both imread and geotiff read give me errors about “Error using rtifc Unsupported sample format 5.”

Thanks.

1 Like

I have the same question can anyone help?

Open the SLC zip file in SNAP, save the file as BEAM-DIMAP. Navigate to the .data folder, the header files (.hdr) contain the information you need to read the SLC .img files in Matlab, replace Y_SIZE with the lines value from the header file, replace X_SIZE with the samples value. The data type is given as an IDL type code, you can look up the code here:

http://www.exelisvis.com/docs/IDL_Data_Types.html

and match the code with the Matlab data type:

https://se.mathworks.com/help/matlab/numeric-types.html

For example if the header gave the data type as 2, this is the IDL code for a 32bit floating point number, then you would replace DTYPE with the Matlab data type float32.

To read a file:
data = multibandread('INPUT_FILENAME.img', [Y_SIZE, X_SIZE, 1], 'DTYPE', '0', 'bsq', 'ieee-be');

To write a file:
multibandwrite(data, 'OUTPUT_FILENAME.img', 'bsq', 'precision', 'DTYPE', 'machfmt', 'ieee-be');

2 Likes

We usually convert the part of the image we are interested via SNAP into a NetCDF file, which is much more convenient to work with in Matlab.

Sven.

2 Likes

The sampleFormat used for SLC products is an extension of the TIFF as defined in:
http://www.awaresystems.be/imaging/tiff/tifftags/sampleformat.html

It seems that most of the tiff API supports the complex float extension but not yet the complex integer extension. This is because (I believe) that the complex integers is not part of the natural types supported by this s/w (matlab, idl, etc).

Tip:
In IDL, the geottiff reader returns for the complex integers an array of integers (it is not failing) having the i/q interleaved which one can then index (odd and even index) to reconstruct a complex float array.

Kind regards
Nuno Miranda
S-1 Data Quality Manager

I have not analysed any S1 IW SLC tiff measurement that didn’t have the actual pixel data immediately after the tiff header in one single block, ie all the images I have looked at (not many) had the following structure: tiff header, followed by the whole pixel data in one single block, followed by the tiff tags. This structure is easily read in binary format (fread in Matlab) and then interpreted following the instructions in Section 6.2.1 of ‘Sentinel-1 Product Specification’ document (and tiff references cited in it).

A couple of caveats:

  • I believe the tiff standard allows for flexible file structures in which the image data can be placed anywhere (ie it has to go behind the header, but not necessarily immediately behind it). Hopefully the S1 tiff writer will not change in the future
  • the header has different size depending on whether it is a normal Tiff or BigTiff. There is a field in the header that indicates which type of Tiff the file is

I am sorry that I tried your approach, but it did not work. In Matlab, the error information says that the input’s type is char which is not supported by multibandread() function. How can I fix this?

It’s impossible to help with so little to go on. You need to post the exact code you used and the error message you received.

Just a couple quick notes: data type of 2 is actually signed 16 bit integer, not 32 bit floating point number.

Also, the 4th argument for multibandread should be 0 without the quotes, or else it won’t work.

Hi Nuno Miranda! I tried to read geotiff S1 with IDL and I obtained an array of integers. I dont understand how I could separate i/q to reconstruct a complex float array if the data array dimesions are the same. Thak’s
Sebastian

There is a tutorial on SAR EDU for DEM generation of SLC SAR data with matlab.
I don’t know if it helps your question but at least there is also data imported.
https://saredu.dlr.de/unit/dem_matlab

@sbstbalbarani
the approach below might not be the most efficient/elegant one but it allows to use IDL geotiff reader

  maskI=ulong('11111111111111110000000000000000'b)
  maskQ=ulong('00000000000000001111111111111111'b)
  r = query_tiff(path_to_S1_geotiff, tiffInfo, geotiff=tiffHead)
 
  ;sub_rect is used to read just a portion of the data
  block = read_tiff(path_to_S1_geotiff, sub_rect=sub_rect)

  ; if the image is SLC then we need to create  complex buffer
 if (tiffinfo.pixel_Type eq 13) then begin
    blockI = fix(block and maskQ)
    blockQ = fix(ishft( (block and maskI), -16))
    block = complex(blockI, blockQ)
  endif

Thanks nuno! I tried to read sentinel-1 geotiff located in measurement directory of SAFE structure with IDL language, but I couldnt. In your code r = query_tiff(… does not recognize the tiff. It is correct? sbst

Hi ABraun,

I implemented the following example using matlab and it worked very nice, but how we could change the parameters of ENVISAT or ERS to the Sentinel-1 specially the burst issues?, SAR-EDU_Tutorial_Focusing_Matlab.pdf (626.0 KB)

unfortunately, I’m not experienced with Matlab, but you could try writing Dr. Stefan Auer as he is quite responsive to SAR related questions.

Hi every body
I have a question
I make a DEM and now, I want to know how i can bring DEM information into matlab?
I want it was like a picture and have elevation value in each pixel!

and another question what is the best way for reading the slc image in matlab?

maybe one of these is helpful to you

http://de.mathworks.com/help/map/ref/sdtsdemread.html;jsessionid=051a0bfb04e4ae55ff963fcb3ca3
https://de.mathworks.com/help/map/ref/geotiffread.html


https://saredu.dlr.de/unit/dem_matlab
https://saredu.dlr.de/unit/focussing_matlab

Thank you so much:slight_smile:

I create ENVI export from my DEM and load hdr file in matlab and read it
but there are some mistake in my read matrix !
when I do terrain correction on my DEM , it is not a complete square image and have black area in border
when I read it in matlab these area have negative values!!
I don’t know how to correct them!

black borders could occur when the DEM used for terrain correction doesn’t fully cover the whole product.
Later on, have a look at the nodata value under the raster’s properties.