An optical satellite measures sunlight reflected from the ground. A cloud sits in the way, and it is a strong reflector of its own. Over a cloud, every band is bright and the near-infrared and red are about equal, so NDVI is close to zero and the pixel looks like bare ground. The numbers contain no error flag. A mean or a map that includes cloud cells is wrong, and nothing on the screen tells you so. For this reason a cloud mask is one of the first steps of any workflow with optical images.
What needs hiding
Cloud is the obvious one, and it comes in three forms. Thick cloud is bright and white in every band. Thin cirrus, high clouds of ice crystals, let some of the ground through and add a haze, and it is hard to see in the colour image. Cloud shadow is a dark patch on the ground next to the cloud, offset from it in the direction away from the sun. A shadow can be mistaken for water or for a burned area, and it lowers every band.
Haze and smoke also change the numbers, without looking like cloud. Snow and ice are bright, and are often marked with the clouds because they confuse the same algorithms.
How the masks are made
Space agencies deliver a classification with every scene. The processing software looks at the bands and sorts each pixel by rules and tests.
Sentinel-2 Level-2A includes the scene classification layer, SCL, a raster with 20 m cells that holds a code from 0 to 11 for each pixel: 0 no data, 1 saturated or defective, 2 dark area, 3 cloud shadow, 4 vegetation, 5 bare soil, 6 water, 7 unclassified, 8 medium probability cloud, 9 high probability cloud, 10 thin cirrus and 11 snow or ice. The cloud mask guide uses it in QGIS and in Python.
Landsat Collection 2 includes a quality band, QA_PIXEL, in which each bit is a yes or no flag: is the pixel cloud, cirrus, cloud shadow, snow, or water, and how confident is the algorithm. You read a flag by checking one bit of the number, as the Landsat guide explains.
Both are produced by an automatic algorithm, and both are made at a fixed time in the processing, with a fixed set of rules. You can also build your own mask from the bands, for example by marking pixels that are bright in blue and white in the infrared, and tools such as s2cloudless use machine learning to do it better than a fixed rule. For most work the supplied mask is the right start.
Which classes to hide
There is no single right answer. The more you hide, the fewer cloud pixels get through and the more good pixels you throw away.
- Hide the sure things first: no data, saturated, cloud shadow, medium and high cloud probability, thin cirrus and snow. This is the standard choice for vegetation work.
- Hide the dark area class as well in hilly country, if shadow from the terrain bothers you.
- Hide unclassified too if you want a very clean result, at the price of losing some good ground.
- Do not hide water unless water is not your subject. Class 6 is real water, and hiding it removes the very thing that a water map needs.
The guide compares four masks on one real scene and shows how much the mean NDVI changes with each one. The scene was 58 percent cloudy, and the choice of mask moves the answer by a visible amount. This is the thing to remember: the mask is part of the method, and you should report which classes you hid.
Why masks make mistakes
The mask is a guess from the images. It fails in known ways:
- Bright ground such as sand, salt flats, white roofs and fresh concrete can be marked as cloud.
- Thin cloud and haze at the edge of a cloud can be marked as clear.
- Cloud shadow is hard, because it depends on the height of the cloud, which the image does not give. The mask guesses it from the position and the direction of the sun, and a small cloud can leave a shadow that nothing marks.
- Snow on the plains is a mistake in itself. A class of snow or ice that appears on the plains of Punjab in November is a sign that the classifier has been fooled.
Because of these mistakes, a mask is a good first filter and not a perfect one. Look at the result as a picture, and compare it with the true-colour image.
What to do with the gaps
A mask leaves holes. A single scene may have only a quarter of the ground left. There are three ways to fill the holes.
- Use another date. If the work is about a season and not a day, take another scene a few days earlier or later.
- Build a composite. Take the median of the clear values of several scenes, pixel by pixel. The median of a month is the standard in time series work, and the raster time series tutorial does exactly this. A cloudy month can still have no clear value for a pixel, and that is better shown as NoData than invented.
- Use radar. Radar sees through cloud, and Sentinel-1 is the usual partner when the monsoon hides the ground for weeks.
Check a mask before you trust it
- Draw the mask over the true-colour image and look for clouds that it missed and ground that it hid.
- Count the share of valid pixels in your study area. If most is gone, the result is weak, and you should say so.
- Compare a result with and without the mask. If the number hardly changes, the mask is not the problem. If it changes a lot, the mask choice needs a sentence in your report.

