Jump to content
PDS Geosciences Node Community
agc5

LROC LOLA Data Import to MATLAB

Recommended Posts

Hello,

I've been struggling with how to process the JP2 images I import into MATLAB. These images are read as int16 types.

For example, 

skyv_65n_240m.jp2

SKYV_65N_240M_JP2.LBL

The values of each pixel are a mystery to me. 

After applying the scaling factor and offset to each DN, the values are still not in steradians. 

I've tried working with several other LROC LOLA data types (roughness and slope maps), but after reading these JP2 files into MATLAB I end up with wonky pixel values.

Any advice is greatly appreciated.

Thank you

Share this post


Link to post
Share on other sites

Hi,

I don't see any product in the LOLA archives with the name SKYV_65N_240M_JP2. Can you give me the URL where you found it?

In general, the JP2 files are JPEG2000 images. You won't be able to read them easily in MATLAB. 

In the LOLA archives, JP2 images are included only for ease of displaying the data. For every JP2 file there is a corresponding IMG file containing the same data in plain raster format, which is readable in MATLAB. The OBJECT = IMAGE section of the label (*.LBL file) tells you the information MATLAB needs to know to read the file, such as number of lines, number of samples per line, size of a sample, and sample type (byte order).
 

Share this post


Link to post
Share on other sites

Hello,

Thank you for getting back to me.

The URL is http://imbrium.mit.edu/EXTRAS/ILLUMINATION/JP2/ . The sky visibility data records are on the bottom of the page. 

I was having more difficulty processing IMG file in MATLAB. I will be needing to take a look at that more. I was working with the JP2 file type, and applying the formula Value = DN* SCALING FACTOR + OFFSET.

My main goal of processing this data is to produce histograms of certain data records to gain an overall understanding of the lunar topography.

 

Share this post


Link to post
Share on other sites

The SKYV* files are in the EXTRAS directory, which means they are not part of the official LOLA PDS archive, and therefore not peer reviewed. They are extra material that users may find interesting or helpful as an addition to the standard data products. 

For the product you mentioned, SKYV_65N_240M, there is an equivalent IMG product in http://imbrium.mit.edu/EXTRAS/ILLUMINATION/IMG/. According to its label, it is a binary array of 6420 by 6420 16-bit LSB signed integers (LSB = least-significant-byte-first = "little-endian"). To go from the DN value to solid angle in steradians, you apply the formula DN*SCALING_FACTOR+OFFSET, where SCALING_FACTOR is 0.0002 and OFFSET is 6.2832. 

Share this post


Link to post
Share on other sites

Hi,

Try to read the IMG as UInt16 LSB type. This may solve your problem. 
I haven't try the IMG data with MATLAB, but I could read them with c# codes. Below is some hint when I read the IMG with C#.

- read the img as binary
- convert the binary data to the right format

            int numPixels = nColumns * nRows * nBands;
            var img = new UInt16[numPixels];

            Byte[] myBytesReordered = new Byte[2];
            for (int i = 0; i < numPixels; i++) 
            {
                int byteImgId = i * 2;
                myBytesReordered[0] = data[byteImgId];
                myBytesReordered[1] = data[byteImgId + 1];
                img = BitConverter.ToUInt16(myBytesReordered, 0);
           }

Attached is the screen capture of my result with 2% linear stretch. Please let me know if you need more help. Thanks,
June 

Capture_LOLA.JPG

Share this post


Link to post
Share on other sites
On 6/23/2020 at 2:32 PM, Susie Slavney said:

The SKYV* files are in the EXTRAS directory, which means they are not part of the official LOLA PDS archive, and therefore not peer reviewed. They are extra material that users may find interesting or helpful as an addition to the standard data products. 

For the product you mentioned, SKYV_65N_240M, there is an equivalent IMG product in http://imbrium.mit.edu/EXTRAS/ILLUMINATION/IMG/. According to its label, it is a binary array of 6420 by 6420 16-bit LSB signed integers (LSB = least-significant-byte-first = "little-endian"). To go from the DN value to solid angle in steradians, you apply the formula DN*SCALING_FACTOR+OFFSET, where SCALING_FACTOR is 0.0002 and OFFSET is 6.2832. 

Hi Susie,

Thank you for noting that the SKYV* files are not peer reviewed. 

I was able to process the SKYV_65N_240M image in MATLAB. The fread function enables to read from an open binary file. From the LINES or FILE_RECORDS line of the label I'm able to determine the size of the array.

fid  = fopen('SKYV_65N_240M.IMG');

data = fread(fid,[LINES, LINES], 'int16','ieee-le');

After applying the formula DN*SCALING_FACTOR+OFFSET, where SCALING_FACTOR is 0.0002 and OFFSET is 6.2832 , the resulting array looks correct and is in a range of steradians. 

It seems that is the process for processing any PDS IMG file type. Is there a bit of detail that I'm missing from reading in the label?

Thank you for your help.

image.png.72132d6f9ecf25d7b04f727d2bf646c3.png

 

Share this post


Link to post
Share on other sites

As June says, the data values are int16, signed 16-bit integers. I think your fread statement looks correct, although I am not a Matlab user. The PDS3 label says SAMPLE_TYPE = LSB_INTEGER, which is defined as a signed integer in the PDS3 data dictionary, although it would have been helpful if the label explicitly declared the samples to be signed. You may assume that LSB_INTEGER and MSB_INTEGER in PDS3 labels always mean signed integers. LSB_UNSIGNED_INTEGER and MSB_UNSIGNED_INTEGER are used when the values are unsigned.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...