ZAP: Non-Interactive Image Median Filter

Form: ZAP source [SIG=f] [SIZE=s] [SIZE=r,c] [BOX=n] [TTY] [MASK] [SURGICAL] [COLS]
source
is the image being worked on.
SIZE=s
sets the size (full width) of a square median window around each pixel to be used in the median filter computation. Default is a 5x5 pixel square box.
SIZE=r,c
sets the size of a rectangular median window around each pixel to be 'r' rows by 'c' columns wide. Default is a 5x5 pixel square box
SIG=f
specifies the rejection threshold in units of the standard deviation within SIZE. Default is 5.
BOX=n
tells ZAP to work only on those parts of the image within the specified box.
TTY
print verbose output while zapping
MASK
masks pixels rather than replacing them with median
SURGICAL
only edit/mask the central pixel of the running median window. Default edits all pixels within the box that meet exceed the filtering threshold.
COLS
will ZAP each row, replacing all pixels on that row with the median

ZAP will edit and/or mask high or low pixels in an image, or perform whole-image median filtering.

For each pixel, ZAP computes the mean, median, and standard deviation of all of the pixels within a 5x5 box centered on that pixel. The SIZE keyword can be used to change the size and aspect ratio of this box. Any pixels within this box deviate by more than 5-sigma (or f-sigma, using the SIG=f keyword) from the median are replaced by the median. If the MASK keyword is given, the pixels are masked rather than replaced. The 'BOX=n' keywords will limit ZAP's attention to that portion of the image within box 'n'.

ZAP will replace all pixels within the current box that exceed the rejection threshold for the region centered on a particular pixel. To only ZAP the pixel at the center of the current filtering window, use the SURGICAL keyword.

If the SIG=0 keyword is given, zap will in effect median smooth the image within the window given by the size command, replacing all pixels by the median of them and their surroundings.

ZAP is a rather drastic command that should be used with great care. In general, ZAP is not a good way to clean an image of cosmic ray events, especially if the images of your objects have sharp cores (e.g., under- or critically-sample stellar images or emission lines). In these cases, it is best to use the interactive TVZAP to edit the bad pixels in an image if there is a small number of these that may be handled interactively. If cosmic rays are a big problem (e.g., like in HST images) and you have multiple images (e.g., CRSPLIT observations), you should use the MEDIAN, BIGMEDIAN, or PICCRS routines, as appropriate. If your observing strategy (or the source of your images) did not allow use of multiple images for statistical cosmic-ray rejection, careful and judicious interactive cleaning using TVZAP is suggested over blind zapping using ZAP.

Examples:

ZAP 1
Do the filtering with 5 by 5 square, adjusting pixels that are 5 sigma away from the median.
ZAP 1 BOX=4
does the same as example 1, but only in the region defined by box 4.
ZAP 1 SIZE=7
considers a 7 by 7 box at each pixel.
ZAP 5 SIZE=1,15
considers a box that is 1 row by 15 columns in size.
ZAP 1 TTY
does the same as example 1, but shows the coordinates of the zapped pixels on the screen.

A related command is TVZAP, which allows you to select which pixels are to be zapped interactively using the TV cursor. LZAP works with a list of known bad pixels.