Comparison between jpg2000 and xml files for Sentinel 2A

Hello everyone!

I compared jpg2000 file of a band and the corresponded band (for the same granule, clearly) into xml file.
I noticed that the spectral range (max, min) is completely different. Values for each pixels are different (coincidently for some pixels jpg have half value of xml file). Please, can you help me to understand? Are both of them (jpg 2000 and xml) TOA reflectances values? Is the QUANTIFICATION_VALUE = 10000 for both of them? May be this problem a matter of compression for jpg?

Thanks and apoligize if answers are yet into the forum.

The quantification value needs to be applied to both. Since S2TBX 4.0 this is done automatically.
From your writing I understand the difference between the values is not just the QUANTIFICATION_VALUE.
Maybe @Nicolas can help further.

Thanks @marpet for your answer. Exactly, the difference between the values is not just the QUANTIFICATION_VALUE. jpg and xml files of each S2A band (for the same band) have different (DN) value! why ?

Hi @Ross,

the quantification value is only applied automatically when the xml product is open. When opening the jp2 image, the metadata (which is present in the xml file) is ignored and no scale factors are used.

The difference between the images should be just the quantification value, but for that, it is necessary to compare the pixel values at the same image level (in SNAP different level of the image are used depending on the zoom).

You can see the level in the lower right corner of the window:

It is possible to check if the pixel values are the same or not by using band maths tool. You can create a new band with the expression:
NewBand = round(Band1FromXML*10000 - Band1FromJP2)

where 10000 is the quantification value and the round operator is used to avoid rounding effects (if you do not use it, you will obtain errors of 0.000X instead of zero).

Please, could you confirm that the reason for the differences is the multilevel image? If not, could you please explain me what product are you using to examine it in detail?


Dear marpet, I have S2TBX 6.0 and I have to convert the ToA and BoA reflectances with “Quantification Value”. This process is not done automatically for me. Please, could you explain me?

This is only done automatically if you open the MTD_MSIL1C.xml file. This is not done when opening one of the *.jp2 files.

Hello, obarrilero.

I’m having trouble now that the reflectance value displayed in snap is different from the reflectance value displayed in python.

There is a double difference.
Is this related to the difference in levels?

L2A images are used in python.
And in the snap, it is displayed as Level-4.

Questions I asked in the past in this forum

Hello @bakeho,

to see the ‘real’ value of the pixels in SNAP, you should visualize the image at level-0, so, please, try to zoom in the pixel till you are in level-0 and then compare the value with the one from python.

And note, that depending on how you are reading the images in python, it could be a different value if the scale factor is not applied (SNAP automatically apply it by dividing the pixel value by 10000 to convert to reflectance).


1 Like

Thank you for your reply.

I compared the value of level0 with the value by python, but there was a difference.

In python, the value is calculated in consideration of the quantified value.

Is this because there are calculations other than quantification?

Or is pyhon not able to handle jp2?