Geoscience Reference
In-Depth Information
--debug
Print debugging information.
We will demonstrate the use of gdal_calc.py first with some basic examples
before entering into themore practical case of calculating a vegetation index. The next
command seems simple at first, but holds a pitfall. We want to calculate the average
of two Byte images. The naive approach would be to calculate the average as:
gdal_calc.py -A input1.tif -B input2.tif --outfile=average.tif
--calc="(A+B)/2"
The problem is that the input images are of type Byte. This means that the result
can only hold values from 0 to 255 (the dynamic range of a Byte). When calculating
(
>
255. You should therefore always check if both the input and output data types are
appropriate for the calculation (one approach would be to replace the calculation
with --calc"(0.5*A+0.5*B)" .
The next example uses a logical operator to replace values 255 with 0.
A
+
B
)/
2,
(
A
+
B
)
is calculated first, which can not fit into a Byte if A
+
B
gdal_calc.py -A input.tif --outfile result.tif
--calc="0*(A==255)+A*(A!=255)"
The calculation reads as: if A (input) equals to 255, set output value to 0; else set
output value to A. The first term (0
(
A
==
255
)
) is redundant. In case the condition
in the second term ( A
!=
255) is not met, the output will automatically obtain the
value 0.
The last example creates a popular index derived from remote sensing images.
The normalized difference vegetation index [(NDVI (Rouse et al. 1973)] is often used
to describe the vegetation status. Green vegetation absorbs incoming solar radiation
as a source of energy for its photosynthesis. The absorption is mostly pronounced in
the red part of the electromagnetic spectrum. Incoming light at wavelengths beyond
700nm is predominantly reflected. As a result, the relative difference between the
reflectance bands in nir, the near infrared part of the electromagnetic spectrum
(700-1,100nm), and red is expected to be higher than for targets where green vege-
tation is abscent.
The following snippet calculates Eq. 11.1 using gdal_calc.py based on the
reflectance bands in red (band 68) and nir (band 116) of the hyperspectral image
2013_IEEE_GRSS_DF_Contest_CASI.tif . We mask areas with no vege-
tation. In particular in urban areas, water bodies and cloud (shadow) can result in
negative NDVI values. Therefore, pixels where the condition nir
red does not hold
will obtain a no-data value (0). This is achieved by multiplying the logical operator
B
>
A with the arithmetic function that calculates Eq. 11.1 and setting the option
--NoDataValue 0 . We scale the floating point result with a factor of 10,000 and
>
 
 
Search WWH ::




Custom Search