I have a water mask (binary code where water==1), and a SAR-derived texture image. I have collocated both in SNAP.
What is a functional bandmath logic to say that “give a value of 9999 to texture band if watermask band==0 (non-water)”?
In other words, I would like to mask out the texture band in terms of water and non-water areas of water mask band.
Any comment is appreciated!
IF water == 0 THEN 9999 ELSE texture
ABraun, I have tested it, but it doesn’t give me what I am looking for. Literally, it gives me the same water mask band with an opposite binary code (now water has the value of 0).
Lets say if my first band water mask holds the value of 0 (land) and 1 (water), I would like to use the water areas (code 1) as an mask to extract the “corresponding areas on another band (like DEM)”. For example, my output would be a DEM file, not a binary water mask.
ABraun’s answer is correct. Because you set the pixel value for land to 9999, it makes the land part very bright and that gives you the impression that you get the opposite of the mask. Try to use -9999 instead to see what you will get.
I know ABraun is correct, but as I explained earlier I am not looking for a new water mask band. I just want to use my water binary band as a new mask to extract a DEM layer only for the corresponding water areas.
screenshots of your bands would help us understand what your goal is.
I think it is about scaling and contrast. If your smallest value is 0 and your largest is 9999 you won’t be able to see the fine details in the texture layer which might only be ranging from 0-5, for example. Use the pixel value tool to see if it is really binary or if the texture was written into the corresponding areas in the first example.
If you want to mask out the values of 9999 then you can set this value as no-data value of the band.
Right-click on it and open the Properties. Change the No-Data Value and also enable No-Data Value Used
Instead of 9999 you also use NaN in your expression, if your data is of a floating point type. Then this value is automatically considered as no-data.
Perhaps I didn’t explain well what I am looking for.
I need to extract from the "DEM band", Only those areas that correspond to water bodies (value 1 in another layer). I thought that I might be able to use my water binary band as a mask to do so.
The nature of the output should be a DEM band (elevation value).
Any comment is truly appreciated!
Here what I have done. I think this what you want and what we explained.
On the left is my altitude (your DEM) on the right my waterMask (Land=0, Water ==1). In the middle is the result is the result of the expression (waterMask == 0 ? altitude : NaN).
marpet, That was exactly what I was looking for. Thank you so much!