next up previous
Next: The Bad-Pixel Flag
Up: BAD PIXELS
Previous: The Need for Bad Pixels

Recognition and Processing of Bad Pixels  

Having been introduced into an array, bad pixels must be recognisable by subsequent algorithms, which must be capable of taking suitable action to allow for the missing pixel values (normally, this will mean disregarding them in an appropriate manner).

For purposes of recognition, bad pixels are assigned a unique value, appropriate to their numeric type and reserved for this purpose. This value is identified by a symbolic name of the form VAL__BADx, where ``x'' identifies the numeric type, as follows:

VAL__BADD -- Bad double-precision pixel value
VAL__BADR -- Bad single-precision pixel value
VAL__BADI -- Bad integer pixel value
VAL__BADW -- Bad word pixel value
VAL__BADUW -- Bad unsigned word pixel value
VAL__BADB -- Bad byte pixel value
VAL__BADUB -- Bad unsigned byte pixel value

(note the use of a double underscore character in this naming convention). These symbolic constants, along with others relating to the HDS primitive numeric types, are defined in the include file PRM_PAR (see SUN/39). The appropriate symbolic name should be used for the numeric type being processed.

To give an example of how the need for bad pixels inevitably arises in practice, consider the following simple algorithm to divide one single-precision (i.e. `_REAL') array A by another B, to give a result in the array C:

      INTEGER I, EL
      REAL A( EL ), B( EL ), C( EL )

      ...

      DO 1 I = 1, EL
         C( I ) = A( I ) / B( I )
 1    CONTINUE

This algorithm is obviously flawed, because if any element of B is zero, then it will fail. However, we can test for this case, and assign bad pixels to affected elements of the output array as follows:

*  Define the VAL__BADx constants.
      INCLUDE 'PRM_PAR'

      ...

      DO 1 I = 1, EL

*  Test for division by zero and assign a bad value to the output array.
         IF ( B( I ) .EQ. 0.0 ) THEN
            C( I ) = VAL__BADR

*  Otherwise, calculate the result normally.
         ELSE
            C( I ) = A( I ) / B( I )
         END IF
 1    CONTINUE

Subsequent algorithms will then need to recognise these bad pixels and take appropriate action. Normally, if a bad pixel is encountered as input to an algorithm, it should automatically generate a corresponding bad pixel for output, a process known as bad pixel propagation. The above algorithm could therefore be adapted to recognise bad pixels in either of the input arrays (A and B) and to propagate them, as follows:

      INCLUDE 'PRM_PAR'

      ...

      DO 1 I = 1, EL

*  If either input pixel is bad, then so is the output pixel.
         IF ( A( I ) .EQ. VAL__BADR .OR. B( I ) .EQ. VAL__BADR ) THEN
            C( I ) = VAL__BADR

*  Check for division by zero.
         ELSE IF ( B( I ) .EQ. 0.0 ) THEN
            C( I ) = VAL__BADR

*  Otherwise, calculate the result normally.
         ELSE
            C( I ) = A( I ) / B( I )
         END IF
 1    CONTINUE

Different action may be required in other algorithms, but the process illustrated here is typical.



next up previous
Next: The Bad-Pixel Flag
Up: BAD PIXELS
Previous: The Need for Bad Pixels


Starlink User Note 33
R.F. Warren-Smith
11th January 2000
E-mail:rfws@star.rl.ac.uk

Copyright © 2000 Council for the Central Laboratory of the Research Councils