Relational, conditional and Boolean operations

To perform per-pixel comparisons between images, use relational operators. To
extract urbanized areas in an image, this example uses relational operators to threshold
spectral indices, combining the thresholds with and():

As illustrated by this example, the output of relational and boolean operators is
either true (1) or false (0). To mask the 0's, you can mask the resultant binary image
with itself. The result from the previous example should look something like Figure 1.

The binary images that are returned by relational and boolean operators can be used with
mathematical operators. This example creates zones of urbanization in a nighttime lights
image using relational operators and image.add():

Observe that in the previous expression example, the band of interest is referenced using
the b() function, rather than a dictionary of variable names. (Learn more
about image expressions on this page. Using either
mathematical operators or an expression, the output is the same and should look something
like Figure 2.

Another way to implement conditional operations on images is with the
image.where() operator. Consider the need to replace masked pixels with some
other data. In the following example, cloudy pixels are replaced by pixels from a
cloud-free image using where():

In this example, observe the use of the simpleCloudScore() algorithm. This
algorithm ranks pixels by cloudiness on a scale of 0-100, with 100 most cloudy.
Learn more about simpleCloudScore() on the
Landsat Algorithms page.