Masking is the process by which you remove pixels in an image based on the properties of that data, or the properties of a different data layer. The built-in cloud masking block (Mask Out Clouds) is an example of a mask -- it masks out (removes) all pixels that contain clouds. That way, any analysis or statistics you apply to the remaining pixels is only being done on the cloud-free pixels.
Other examples of masking might include:
- Masking out everything that is not forest cover so that you only analyse forest pixels.
- Removing everything but a lake feature so you can analyse the water properties only.
- Excluding any pixels that reach a certain threshold value.
Here we focus on how to mask pixels using the mask tool, but for completeness, we also include a short description of how to do it (and more advanced masking) using the calculator tool.
The mask tool can be found in the Toolbox under Input->Filter->Mask Out Part of Image.
TABLE OF CONTENTS
- Masking data within a workflow using Mask Out Part of Image block
- Masking data from another workflow using Mask Out Part of Image block
- Using the Calculator Block to Mask out Data
Masking data within a workflow using Mask Out Part of Image block
- Within a workflow, add the Mask block.
- It will automatically identify which data layers are available and offer them in the drop-down menu.
- If you choose an image data layer, it will automatically give you numeric options based on criteria (less then, greater than, etc). Enter the number you want as the threshold.
- If you choose a thematic layer (such as a land classification) you will get a drop-down menu that includes all the classes.
- The wording on the block is important: pixels that meet the criteria will be taken out of the data layer.
Masking data from another workflow using Mask Out Part of Image block
- This works in the same way as above, except that the other data layer has to be imported into the workflow you are working on.
- To do this, use a Save Data for Re-use block within the workflow that has the data you want to use for setting the masking criteria.
- Then add this saved data into your other workflow using Re-use This Saved Dataset.
- As an example, imagine you wanted to examine some Sentinel 1 data, but you only wanted to analyse those areas with forest cover. The following two workflows achieve that:
- The first workflow on the left draws in the Hansen tree cover map and saves it for re-use.
- The second workflow brings in Sentinel 1 data and the tree cover map.
- It then uses the Mask Out Part of Image block to mask out any Sentinel 1 data that is co-incident with data less than 25% tree cover.
Using the Calculator Block to Mask out Data
- Within the calculator block, you can use mask(image1, image2) to apply a mask to image1. If image 2 is an image layer with values from 0-1, then the mask will have varying transparency, with 1=fully opaque, and 0 being fully transparent.
- You can create the masking image (image2) in one of two ways in the Calculator block:
- The easiest way is to enter a simple Boolean expression, such as DATA > 5 (where DATA is the chosen variable from an available data layer). The output layer will then be a layer that is equal to 1 where the expression is true (in this case, DATA is greater than 5) and zero everywhere else.
- This output layer can then be used as the mask layer, image2, in the expression above as it meets the criteria of being between 0 and 1.
- On its own, this does not have a mask, it merely has a set of zeros and ones. When used with mask(image1, image2) it will mask out all those areas that are not "true".
- Note that this expression can have other Boolean logic expressions such as OR and AND. For example, the expression DATA >= 2 AND DATA <=5 will return 1 for all pixels between 2 and 5, and zero everywhere else.
- You can use the more elaborate IF-THEN-ELSE expression using ? and : so that you will have: DATA >5 ? 1 : 0. The output layer from the Calculator Block is then the same as above.
We always track the feedback you give us so that we can improve how we help you.
Please let us know if you found this one helpful.
Was this article helpful?
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
We appreciate your effort and will try to fix the article