How do I create an Input Mask?

In some of the algoritms that I’ve been looking at it gives the option to mask an image.

Input Mask -mask image
The mask restricts the classification of the input image to the area where mask pixel values are greater than 0.

What format does this need to be in? Does it need to be a raster with 0 and 1 values?

How would I go about creating this?

Hello,

You can have a look at the BandMath application. It performs pixel based image operation and you can use it to create a mask, for example, the expression :

im1b1 > 150 ? 0 : 1 can be used to create a binary raster masking all pixels that have their first band value superior to 150.

Hope that helps,
Cédric

Thanks Cedric. I have a satellite image and I want to mask out the no value areas surround it that are black in colour.
How would I use band math to give a value of 0 to the no value areas and a value of 1 to those areas with information?

If the no data value is written into the meta data of your image, you can use the ManageNoData in buildmask mode, to produce a mask based on no data value.

For example (in command line) :

otbcli_ManageNoData -in input.tif -out mask.tif  -mode buildmask -mode.buildmask.inv 0  -mode.buildmask.outv 1

Note the inv and outv parameter respectively set to 0 and 1, to correctly set no data pixel to 1 in the output mask

Alternatively, With Bandmath it would be something like :

-exp "(im1b1==-999 || im1b2==-999 ) ? 1 : 0"

here the no data value is -999. Only two bands are tested here, you would need to adapt the code to your image.

Great thanks Cedric!