Create mask with radiometric indices

#1

Hello,
I am looking to create a mask for water with OTB. I found several things in OTB Cookbook :
RadiometricIndices and Feature extraction.

I used the otbcli_RadiometricIndices function, inputting a hypercube that I created with the different Sentinel-2 images corresponding to each band. I’m looking to make a mask for the water so I used -list Water:NDWI (I also tested with NDWI2).
Unfortunately, the image created at the output is all black. I don’t understand how this function works and what the values to put in the different channels (R, V, B, NIR and MIR) correspond to.

Could you help me understand how this function works and how I can successfully make a mask using radiometric indices of interest?

Thank you in advance.
Camille

0 Likes

#2

Hello,

the channel parameter should be used to specify which band corresponds to which spectral channel. In the case of a 12 band Sentinel 2 cube, where the first band correspond to B01, the second to B02 etc, you should set it as :

  • channels.blue : 2
  • channels.green : 3
  • channels.red : 4
  • channels.nir : 8 (near infrared)
  • channels.mir : 11 or 12 (medium infrared)

Note that you only need to set the channels that will actually be used to compute the requested indices. Here NDWI is (nir-mir)/(nir+mir) and NDWI2 is (green-nir)/(green+nir). According to wikipedia, NDWI2 is more suitable to build a water mask (NDWI can be used to monitor water content in vegetation).

In command line you can do :

otbcli_RadiometricIndices -in S2A.tif -out NDWI.tif -channels.green 3 -channels.nir 8 -list Water:NDWI2

Hope that helps

0 Likes

#3

Thank you very much.

I created my hypercube with only my bands 2, 3, 4, 5, 6, 7, 8, 8A, 11 and 12. So my image has 10 bands where band 2 is the first. Does this mean I have to put “channels.blue 1”… etc. ? Since band 1 of my hypercube corresponds to my band 2 of the Sentinel data.

0 Likes

#4

Exactly!

If you want to create a mask from the NDWI image, you can use the Bandmath application to apply a threshold on the output of RadiometricIndices.

0 Likes

#5

I looked at the documentation on BandMath and I had also found this site : Images with no-data values

I also looked at how to apply a threshold with BandMath but I can’t find a way to do it. Do you think about the same method as in the link “Images with no-data value” that uses ManageNoData ? Or do we have to use an expression or something else ?

0 Likes

#6

Where should I put expressions like that “if((b4-b3)/(b4+b3) > 0.4, 255, 0)” or “(b4-b3)/(b4+b3) > 0.4) ? 255 : 0”)" in BandMath ?

0 Likes

#7

BandMath is the “calculator” application of OTB, and it can be used to perform many pixelwise operation on input image. To perform thresholding, you need to use it as follow:

otbcli_BandMath -il NDWI.tif -out waterMask.tif -exp 'im1b1 >0.5'

  • il is the input image list, here you only have one image.

  • out is the output image

  • exp is the expression to be applied on each pixel. im1b1 means first image and first band, and the logical expression im1b1>0.5 is evaluated on each pixel (I’m not sure about the 0.5 value, it depends on the NDWI value.

This will create a binary mask image, where 1 corresponds to water and 0 to land.

The ManageNoData application can be used to manipulate the no data flag of the image. For example you can use it on the input image along with the created mask to modify all water pixel to the no data value. Depending on what you want to do, you might want to use this application, but be aware that many applications in OTB won’t take the no data flags into account.

The second one

1 Like

#8

Thank you very much, I think all this will help me a lot !

0 Likes

#9

Would you have a method to estimate the threshold value to be used ?
I search in the literature but it’s not always easy to find values.

0 Likes

#10

According to this source, water bodies have NDWI>0.5, while vegetation usually have negative values. Built up areas have values between 0 and 0.2.

So maybe something like 0.3 is a good value ?

Also according to this paper, if your image has a lot of built up areas, you might want to use MNDWI (also available in OTB!), it uses the green and MIR channels (B03 and B11 if I’m correct).

0 Likes

#11

Thank you, I found the same source and indeed 0.3 is a good value to get my water mask with the NDWI2.

I am now looking for a good threshold for the NDBI which tends to take bare ground in addition to urban. I have tested several values between 0 and 0.2 but I don’t think I could have anything perfect. I’m thinking of testing the Index Surfaces Built to see if I can get something better.

0 Likes

#12

I found this for the ISU index (here) : ISU = A + B * (R/NIR).

For SPOT, A and B are apparently constants worth 100 and 25 respectively but it is impossible to find their value with Sentinel 2. Do you know anything about this index? because I can’t find anything on the internet.

0 Likes