FPR

Programmable filter


EnvironmentsPYTHON :: EASI :: MODELER
Quick linksDescription :: Parameters :: Parameter descriptions :: Details :: Example :: Related

Back to top

Description


FPR performs programmable filtering on image data, averaging the data according to weights you specify.
Back to top

Parameters


fpr(file, dbic, dboc, flsz, mask, fltfil, bgzero, mr01, mr02, mr03, mr04, mr05, mr06, mr07, mr08, mr09, mr10, mr11)

Name Type Caption Length Value range
FILE * str Input file name 1 -    
DBIC * List[int] Input raster channel or layer 1 - 1  
DBOC * List[int] Output channel or layer 1 - 1  
FLSZ List[int] 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 List[int] Area mask layer or channel 0 - 4  
FLTFIL str Text file of filter weights 0 - 191  
BGZERO str Set background to zero 0 - 3 Yes, No
Default: Yes
MR01 List[float] Row 01 of the filter matrix 0 - 11  
MR02 List[float] Row 02 of the filter matrix 0 - 11  
MR03 List[float] Row 03 of the filter matrix 0 - 11  
MR04 List[float] Row 04 of the filter matrix 0 - 11  
MR05 List[float] Row 05 of the filter matrix 0 - 11  
MR06 List[float] Row 06 of the filter matrix 0 - 11  
MR07 List[float] Row 07 of the filter matrix 0 - 11  
MR08 List[float] Row 08 of the filter matrix 0 - 11  
MR09 List[float] Row 09 of the filter matrix 0 - 11  
MR10 List[float] Row 10 of the filter matrix 0 - 11  
MR11 List[float] Row 11 of the filter matrix 0 - 11  

* Required parameter
Back to top

Parameter descriptions

FILE

The name of the file to process.

DBIC

The input channel or layer to filter.

DBOC

The output channel or layer to receive the output results.

The output channel or layer can be the same as the input channel or layer, and you can also specify more than one of either, if necessary.

Only the area under the mask is processed. If no mask is specified, FPR filters the entire channel.

FLSZ

The horizontal and vertical dimensions of the filter, in pixels. You can specify odd integers ranging from 1 through 33, inclusively. The filter need not be square. The minimum filter size is 1 x 3 or 3 x 1. The default size is 3 x 3 (3,3).

This parameter is optional.

MASK

The area in the input image to filter.

This parameter can be set by specifying a window size or a bitmap mask channel.

A window mask is specified as follows:
MASK=x-offset, y-offset, x-size, y-size

X-offset and y-offset define the upper-left starting pixel coordinates of the window. X-size is the number of pixels that define the window width. Y-size is the number of lines that define the window height.

If no bitmap is specified, the entire layer is processed.

This parameter is optional.

FLTFIL

The name of the text file that contains the filter weights that are used for a filter you have defined. The text file is a space-delimited matrix of weight values that correspond to the window size of the filter.

Each line of the text file must contain the coefficients of the corresponding row of the filter. Field i of line j of the text file must contain the coefficient of row j, column i of the filter. The fields must be whitespace-delimited.

Note: If the filter matrix-row parameters 01 through 11 are specified, this parameter is ignored.

BGZERO

Whether to set the background to zero or to keep the value outside the specified mask area.

If you use the default setting of the MASK parameter, this parameter is ignored.

MR01

The row elements of the filter matrix.

For more information, see Details.

MR02

The row elements of the filter matrix.

For more information, see Details.

MR03

The row elements of the filter matrix.

For more information, see Details.

MR04

The row elements of the filter matrix.

For more information, see Details.

MR05

The row elements of the filter matrix.

For more information, see Details.

MR06

The row elements of the filter matrix.

For more information, see Details.

MR07

The row elements of the filter matrix.

For more information, see Details.

MR08

The row elements of the filter matrix.

For more information, see Details.

MR09

The row elements of the filter matrix.

For more information, see Details.

MR10

The row elements of the filter matrix.

For more information, see Details.

MR11

The row elements of the filter matrix.

For more information, see Details.

Back to top

Details

FPR performs programmable filtering on image data. The programmable filter averages image data according to weights you have specified. By using FPR, you can design filters for specific requirements, such as directional filters or Laplacian filters. The filter dimensions must be odd, with acceptable values ranging from 1 x 1 through 33 x 33. You must specify a matrix of real weights to apply to each pixel within the filter area. FPR does not normalize the filter weights.

Each row of the filter matrix is stored in a separate parameter (MR01, MR02, MR03...MR11).

The output channel or layer can be the same as the input channel or layer.

The MASK parameter specifies the area within the input channel to process. Only the area under the mask is filtered. The rest of the image is unchanged.

If you specify a single value for the MASK parameter, the value points to a bitmap segment that defines the area to filter. When you specify four values, the values define the x and y offsets and x and y dimensions of the rectangular window in the image to filter. By default, MASK processes the entire image.

Filter-matrix parameters

The filter-matrix parameters 01 through 11 define the matrix-row elements.

The implementation of a programmable filter consists of applying a set of weighting values (M) for each pixel (P) that you define. All pixels are filtered. To filter pixels located near the edges of the image, FPR replicates edge-pixel values to provide sufficient data.

Filtered window 3 x 3Weight values set by you
           	    +---------+             +---------+
           	    |P1 P2 P3 |		    |M1 M2 M3 |
       	            |P4 P5 P6 |             |M4 M5 M6 | 
       	            |P7 P8 P9 |		    |M7 M8 M9 |
	            +---------+		    +---------+  
    

The resulting gray-level value R for the smoothed pixel is:

R = (P1*M1 + P2*M2 + ... +  P9*M9) / (M1 + M2 + ... + M9)        
where:

If the sum of filter weights is zero ( M1 + M2 + ... + M9 = 0):

R = (P1*M1 + P2*M2 + ... +  P9*M9)

The following example applies a Laplacian mask Q on a 3 x 3 filter area of an 8 x 8 image:

                                    +---------+                
                                    | 0 -1  0 |		   
                                    |-1  5 -1 |                
                                    | 0 -1  0 |		   
                                    +---------+		    

	    Image before filtering           Image after filtering

	    8  8 9 9 9 7 6 6 6   6 
              +----------------+             +--------------------+
	    8 |8 9 9 9 7 6 6 6 | 6           | 7 10  9 13 7 5 6 6 |
	    8 |8 9 9 7 6 6 6 6 | 6           | 6 11 12  5 4 6 6 6 |   
	    9 |9 8 8 6 6 6 6 6 | 6           |11  6 10  2 6 7 6 6 |
	    9 |9 8 7 7 6 5 6 6 | 6           |12  9  5 10 6 1 7 6 |
	    7 |7 7 7 6 6 6 6 6 | 6           | 6  7  9  4 6 7 6 6 |
	    6 |6 6 6 6 6 6 6 6 | 6           | 5  5  5  6 6 6 6 7 |   
	    6 |6 6 6 6 6 6 6 5 | 5           | 6  6  6  6 6 6 7 1 |
	    6 |6 6 6 6 6 6 6 6 | 6           | 6  6  6  6 6 6 6 7 |
              +----------------+             +--------------------+        
	    6  6 6 6 6 6 6 6 6   6 
Note: In the leftmost example, Image before filtering, columns and scan lines outside the box represent the last image column or scan line being reused, in cases where the filter does not have a full window.
Back to top

Example

A 3 x 3 programmable filter (Laplacian mask Q) is used under 8-bit signed channel 1, which contains blue-green data, and uses the file irvine.pix. The Laplacian mask Q filter computes the Laplacian edge enhancement and adds it back to the original image. The output channel equals the input channel.

from pci.fpr import fpr

file = 'irvine.pix'
dbic = [1]                #channel to be filtered
dboc = [1]                # overwrite input channel
flsz = [3,3]              #Uses a 3 x 3 filter
mask = []                 #Process entire image
fltfil = ''               #No text file of filter weights
bgzero = ''               #Defaulted to Yes, set background to zero
mr01 = [0,-1,0]           #
mr02 = [-1,5,-1]          #Laplacian Mask Q
mr03 = [0,-1,0]           #
mr04 = []
mr05 = []
mr06 = []
mr07 = []
mr08 = []
mr09 = []
mr10 = []
mr11 = []

fpr(file, dbic, dboc, flsz, mask, fltfil, bgzero, 
    mr01,mr02,mr03,mr04,mr05,mr06,mr07,mr08,mr09,mr10,mr11)

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