FME

Median filter


EnvironmentsPYTHON :: EASI :: MODELER
Quick linksDescription :: Parameters :: Parameter descriptions :: Details :: Examples :: Algorithm :: Related

Back to top

Description


FME performs median filtering on image data. The median filter smoothes image data, while preserving sharp edges.
Back to top

Parameters


Name Type Caption Length Value range
FILE * String Input file name 1 - 192  
DBIC * Integer Input raster channels 1 -    
DBOC * Integer Output filtered image channel 1 -    
FLSZ Integer Filter size 0 - 2 1 | 3 | 5 | 7 | 9 | 11 | 13 | 15 | 17 | 19 | 21 | 23 | 25 | 27 | 29 | 31 | 33
Default: 3,3
MASK Integer Area mask 0 - 4
BGRANGE Float Background value range 0 - 2  
FAILVALU Float Failure value 0 - 1  
BGZERO String Set background to zero 0 - 3 YES | NO
Default: YES
MONITOR String Monitor mode 0 - 3 ON, OFF
Default: ON

* Required parameter
Back to top

Parameter descriptions

FILE

Specifies the name of the PCIDSK file that contains channels to filter.

DBIC

Specifies the input channels to filter.

DBOC

Specifies the output channels to receive the filtered result.

The output channels (DBOC) can be the same as the input channels (DBIC). If a mask is specified, only the area under the mask is written to the output channels.

FLSZ

Optionally specifies the horizontal and vertical dimensions of the filter, in pixel units. Acceptable values are odd integers from 1 to 33, inclusively. The filter need not be square. Minimum filter sizes are 1x3 or 3x1; the default size is 3x3.

MASK

Optionally specifies the window or bitmap that defines the area to be processed within the input raster. If this parameter is not specified, the entire channel is processed.

If a single value is specified, that value represents the segment number of the bitmap in the input file. All the pixels within the specified segment, having a pixel value of 1, define the area to be processed.

If four values are specified, they define the X,Y offsets and X,Y dimensions of a rectangular window identifying the area to process. Xoffset, Yoffset define the upper-left starting pixel coordinates of the window. Xsize is the number of pixels that define the window width. Ysize is the number of lines that define the window height.

Only the area under the mask is written to the output. Pixels that are outside the mask but within the filter size window will be used to determine the output pixel values.

BGRANGE

Specifies how the background pixels are processed. Background pixels can be identified as not being covered by a mask or background range you specify. If neither a mask nor a background range are specified, BGZERO is ignored. By default, background pixels will be set to the NoData of the output channel, or zero when NoData is not defined. Alternatively, by specifying BGZERO=NO, the background pixels will not be altered in the output and the value of the pixels prior to processing is retained.

FAILVALU

Specifies the failure value; this value is not used in the calculation.

BGZERO

Specifies how to set the background value outside the specified mask area. A value of YES will set the value to the output channel background value if it exists or 0 if it does not exist. A value of NO will keep the input value. If a MASK is not specified, this parameter is ignored.

MONITOR

The program progress can be monitored by printing the percentage of processing completed. A system parameter, MONITOR, controls this activity.

Available options are:

Back to top

Details

The median filter computes the median value of the gray-level values within a rectangular filter window that surrounds each pixel. This has the effect of smoothing the image and preserving edges. The dimensions of the filter window (FLSZ) must be odd. The minimum filter size is 1x3 and the maximum allowed filter size is 33x33. The filter window need not be square. The input channel (DBIC) can be the same as the output channel (DBOC).

The MASK parameter specifies the area in the input channel that is processed. If no mask is specified, the entire image is processed by default.

Back to top

Examples

Use a 5x5 median filter under bitmap 11 (Urban area) on 8-bit database channel 4 (near infra-red) using irvine.pix. Only the area under the bitmap is filtered and transferred to the output channel.

EASI>file	=	'irvine.pix'	! input file
EASI>dbic	=	4	! near infra-red channel
EASI>dboc	=	8	! output channel
EASI>flsz	=	5,5	! 5x5 filter
EASI>mask	=	11	! bitmap mask segment
EASI>bgrange	=	0	! remove background values from calculation
EASI>failvalu	=	
EASI>bgzero	=		! default, YES

EASI>run FME

Use a 5x5 median filter under 16-bit unsigned channel 10 (which contains elevation data), using irvine.pix. The output channel is the same as the input channel.

EASI>file	=	'irvine.pix'
EASI>dbic	=	10	! elevation data channel
EASI>dboc	=	10	! same as input channel
EASI>flsz	=	5,5	! 5x5 filter
EASI>mask	=		! process entire image
EASI>bgrange	=	
EASI>failvalu	=	
EASI>bgzero	=	

EASI>run FME
Back to top

Algorithm

The implementation of a median filter consists of computing the average of the gray-level values in a square or rectangular filter window that surrounds each pixel.

All pixels are filtered. To filter pixels located near the edges of an image, edge pixel values are replicated to provide sufficient data.

         +--------+
         | 5 3 11 |
         |12 4  9 |     <---    A 3x3 filter window.
         | 8 6 14 |
         +--------+

The median filter finds the 'middle' pixel value in an ordered set of values, below and above, where there is an equal number of values. For example, 8 is the median value for the following set of values: 3,4,5,6,(8),9,11,12,14.

The following example shows a 5x5 median filter used on an 8x8 pixel database.

     Image before filtering       Image after filtering

   8 8  8 9 9 9 7 6 6 6   6 6
   8 8  8 9 9 9 7 6 6 6   6 6
       +----------------+           +----------------+
   8 8 |8 9 9 9 7 6 6 6 | 6 6       |8 9 8 8 6 6 6 6 |
   8 8 |8 9 9 7 6 6 6 6 | 6 6       |8 8 8 7 6 6 6 6 |   
   9 9 |9 8 8 6 6 6 6 6 | 6 6       |8 8 7 7 6 6 6 6 |
   9 9 |9 8 7 7 6 5 6 6 | 6 6       |8 7 7 6 6 6 6 6 |
   7 7 |7 7 7 6 6 6 6 6 | 6 6       |7 7 6 6 6 6 6 6 |
   6 6 |6 6 6 6 6 6 6 6 | 6 6       |6 6 6 6 6 6 6 6 |   
   6 6 |6 6 6 6 6 6 6 5 | 5 5       |6 6 6 6 6 6 6 6 |
   6 6 |6 6 6 6 6 6 6 6 | 6 6       |6 6 6 6 6 6 6 6 |
       +----------------+           +----------------+        
   6 6  6 6 6 6 6 6 6 6   6 6      
   6 6  6 6 6 6 6 6 6 6   6 6

In the image before filtering on the left, columns and scanlines outside the box represent the last image column or scanline that is reused where the filter does not have a full window.

© PCI Geomatics Enterprises, Inc.®, 2026. All rights reserved.