| Environments | PYTHON :: EASI :: MODELER |
| Quick links | Description :: Parameters :: Parameter descriptions :: Details :: Example :: Algorithm :: References :: Related |
| Back to top |
| Back to top |
sarseg(file, dbicim, dbocseg, dbocwrk, maxiter, edgthr, sobthr, dosrd, sthresh)
| Name | Type | Caption | Length | Value range |
|---|---|---|---|---|
| FILE * | str | Input detected SAR image | 1 - | |
| DBICIM * | List[int] | Input SAR image channel | 1 - 1 | |
| DBOCSEG * | List[int] | Output region IDs channel | 1 - 1 | |
| DBOCWRK * | List[int] | Output region means channel | 1 - 1 | |
| MAXITER | List[int] | Maximum number of iterations | 0 - 1 | 1 - Default: 20 |
| EDGTHR | List[float] | Edge detection threshold | 0 - 1 | Default: 4.6 |
| SOBTHR | List[float] | Sobel filter edge selection threshold | 0 - 1 | Default: 2.0 |
| DOSRD | str | Detect small regions | 0 - 3 | YES | NO Default: YES |
| STHRESH | List[int] | Minimum region size (pixels) | 0 - 1 | 0 - Default: 0 |
| Back to top |
FILE
Specifies the name of the PCIDSK file that contains the SAR image to segment. This file will also be updated with the output.
DBICIM
Specifies the SAR image channel to be segmented. This channel should contain SAR backscatter values in the power or intensity scaling. For some images, the amplitude scaling may also work well.
DBOCSEG
Specifies the output channel to receive the region IDs for each region. This channel must exist and be 16U.
DBOCWRK
Specifies the output channel to receive the mean values for each region. This channel must exist and be 32R.
MAXITER
Optionally specifies the maximum number of iterations to be performed by the segmentation algorithm.
Normally, the algorithm executes until the total standard deviation of the image stops decreasing. Total standard deviation is defined as a weighted mean of standard deviations of all regions, each weighted by the number of pixels in the region. If this parameter is set, the algorithm stops after the specified number of iterations, even if the total standard deviation is still decreasing.
EDGTHR
Optionally specifies the edge detection threshold used in the RGW algorithm.
Increasing this value decreases the number of accepted edges, thus decreasing the total number of regions found in the image.
SOBTHR
Optionally specifies the threshold used to select edge pixels after the Sobel filter stage.
For each pixel of the edge intensity map, its immediate 9x9 neighborhood is examined. If the pixel value is greater than the neighborhood mean plus this threshold value multiplied by the neighborhood standard deviation, it is set to 1 and labeled as an edge pixel; otherwise, it is set to 0.
Increasing the value of this parameter decreases the number of accepted edges, thus decreasing the total number of regions found in the image.
DOSRD
Optionally specifies whether to detect small regions.
If small regions are detected, segmentation will include finer polygons, although this will also create more segments to analyze.
STHRESH
Optionally specifies the size, in pixels, of the smallest region not to be merged into a neighbor.
Setting this parameter decreases the total number of regions in the output, but results in a loss of some small but potentially distinct targets. If the value is set to 1 or lower, region merging is not performed.
| Back to top |
SARSEG segments a SAR image into regions based on the edge-detection segmentation algorithm described in the paper cited in References. This function is meant to be used in conjunction with SARCLASS to classify SAR images.
The resolution of the input image should correspond to the physical resolution of the sensor on the ground, as opposed to pixel size of the standard (oversampled) SAR image products.
The output of this function is in two channels: the 16U channel (DBOCSEG) labels each pixel using the ID of the region containing the pixel, and the 32R channel (DBOCWRK) sets each pixel to the value of its region mean. The output channels are intended to be used as input for SARCLASS, which assigns individual regions to one of several classes based on a set of training regions for each class.
| Back to top |
In this example, the 32R sigma-calibrated intensity from a Radarsat-2 image will be segmented into regions. The raw image has already been calibrated and ingested to PIX format, and two channels 16U and 32R will be added, to store the output.
from pci.sarseg import sarseg file = "RADARSAT2/standard_hh_hv.pix" dbicim = [3] # use calibrated sigma-nought intensity from ch3 dbocseg = [4] # store segment IDs into channel 4 dbocwrk = [5] # store segment means into channel 5 maxiter = [] # disregard number of iterations edgthr = [] # use default value of 4.6 sobthr = [] # use default value of 0 dosrd = "" # detect small regions sthresh = [] # include regions of any size sarseg(file, dbicim, dbocseg, dbocwrk, maxiter, edgthr, sobthr, dosrd, sthresh)
| Back to top |
SARSEG implements the algorithm outlined in the R.G. White paper cited in References. At the beginning, the entire image is treated as one segment. During successive iterations, the image is divided into an increasing number of segments, until one of the termination criteria is met, as described below.
First, a 3x3 Sobel filter is run on the image to produce an edge intensity map. All pixels with values above a defined threshold are kept as edge pixels and set to 1, and all pixels below this value are set to 0.
After the Sobel filter has been applied, the main processing loop begins. This loop continues until the total standard deviation stops decreasing, or until the specified number of iterations has been achieved.
The first step in the main processing loop is edge detection. Edge detection windows ranging in size from 7x3 to 57x13 are applied to each pixel both horizontally and vertically. The sum of each half of the window is calculated. All edge pixels and all pixels behind these edge pixels are screened out, and not included in the calculation. If the difference in mean between the two halves normalized by the standard deviation of the region is greater than the defined edge detection threshold, the current pixel is set to an edge pixel.
The next step is to remove isolated edge pixels, which have no neighboring edge pixels. Because this algorithm is meant to segment noisy images, it is likely that many erroneous edges will be initially set. The removal of isolated edge pixels eliminates most of these erroneous edges.
After edge detection, small region detection is performed, only on the first iteration. Small region detection is performed only if small region detection (DOSRD) is set to YES (True). In small region detection windows sized 4x1, 4x3, 4x5 and 4x7 are applied to each non-edge pixel horizontally and vertically. A is the first row (for the horizontal window) or column (for the vertical window), B is the second row or column, C is the third and D is the fourth.
For example:
if ( (mean(A) - mean(B))/std_dev > edgthr
AND (mean(B) - mean(D))/std_dev > edgthr )
set the centre pixel in B as small region
if ( (mean(C) - mean(D))/std_dev > edgthr )
set the centre pixel in C as small region
endif
endif
In small region detection, windows are applied to each non-edge pixel horizontally and vertically to identify small, isolated regions. Pixels found in this step are labeled as small regions, preventing their marking as edges in subsequent processing.
The next step is region growing. A series of templates, from largest to smallest, are passed over the image. Templates are either disc-like, ranging in size from 64x64 to 6x6, or square, ranging in size from 4x4 to 1x1. If a template does not cover any edge pixels, the template is processed. When processing the template, if the template covers no regions, a new region is created and all pixels under the template are set to this region. Otherwise, the pixels under the template are set to the region under the template that the mean matches most closely. The 1x1 template is only used if DOSRD is set to NO.
When the main processing loop is finished, all edge pixels are then assigned to regions. Each edge pixel is assigned to the neighboring region having the mean closest to the edge pixels value.
If the minimum region size (STHRESH) is set to a value greater than 1, sieving is performed next. In the sieving stage, all regions smaller than the specified threshold are merged into the neighboring region with the closest mean.
At the end of each iteration, the termination criteria is verified. If the maximum number of iterations is specified and the required number of iteration has been performed, the execution stops. Otherwise, the total standard deviation of the segmented image at the current iteration is compared with the value at the previous iteration.
If the current value is lower, the next iteration is performed; otherwise the process terminates, and the results of the current iteration are discarded.
At the end of processing, the region ID and mean value of each region are written to every pixel in the appropriate output channels.
| Back to top |
White, R.G., 1986. Low Level Segmentation of Noisy imagery, DRA Memorandum 3900.
© PCI Geomatics Enterprises, Inc.®, 2026. All rights reserved.