DILATEBIT

Dilate and erode bitmap


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

Back to top

Description


DILATEBIT performs morphological operations (dilation and erosion) on a bitmap layer and, optionally, fills unmasked areas, removes masked areas, or both.
Back to top

Parameters


dilatebit(fili, dbib, filo, dbob, size, sthresh, dbsd)

Name Type Caption Length Value range
FILI * str Name of input file 1 -    
DBIB * List[int] Segment number of input bitmap 1 - 1  
FILO * str Name of output file to modify or create 1 -    
DBOB List[int] Segment number of modified bitmap in output file 0 - 1  
SIZE List[int] Size of dilation, erosion, or both 0 -    
STHRESH List[int] Threshold sizes of unmasked areas to fill or masked areas to remove 0 - 2  
DBSD str Description of output bitmap segment 0 -    

* Required parameter
Back to top

Parameter descriptions

FILI

The name of the file that contains the bitmap layer to process.

DBIB

The segment number of the bitmap of the input file to process.

You can specify only one segment number.

FILO

The name of the file to which to write the modified bitmap segment.

The name you specify can be that of the input file, an existing file, or a new file you want to create.

If the file name you specify is that of the input file, and you do not specify the segment number for the output file, a bitmap layer will be added automatically to the input file. If you specify the segment number for the output file with the DBOB parameter, the corresponding bitmap layer must exist already in the output file. If you opt to create a new file, a single bitmap layer will be written to the output file. If you specify an existing file, the bitmap will be the size of the overlapping area.

DBOB

The number of the segment to which to write the modified bitmap.

If you do not specify a value, a new segment is created in the output file you specify.

The value you specify cannot be the same as that of the input segment.

SIZE

The number of pixels by which to dilate or erode the bitmap, or both.

To dilate (grow) areas of the bitmap that are set, enter a positive integer.

To erode (shrink) areas of the bitmap that are set, enter a negative integer.

Note: Each operation must be separated by a comma.

To fill unmasked areas or remove masked areas, enter a value of 0 (zero).

If you want to neither dilation nor erosion, do not enter a value; that is, leave the parameter blank.

You can specify more than one value. By doing so, each operation is applied in the order you specify.

STHRESH

The threshold size, in pixels, at which to fill masked areas of the bitmap after applying dilation and erosion.

You can specify zero, one, or two values. The first value you specify removes voids (unset bits) of an area at the threshold size or less. The second value you specify removes "islands" (set bits) of an area at the threshold size or less.

To remove only islands, and not voids, enter 0 (zero) as the first value.

DBSD

The description of the output bitmap segment.

Back to top

Details

DILATEBIT performs morphological operations (dilation and erosion) on a bitmap layer and, optionally, fills unmasked areas, removes masked areas, or both that are smaller than an area, in pixels, that you specify. You specify the sequence of processing with the SIZE parameter.

The input and output bitmap cannot be the same segment.

The dilation and erosion is relative to the set bits of the bitmap.

If a series of dilation and erosion steps are performed, the output is based on the result of the previous step.

The steps to fill voids, remove islands, or both are based on the threshold you specify.

The sequence of processing is as follows:
  1. Dilation and erosion
  2. Fill voids
  3. Remove islands

You can neither interleave nor reorder the dilation and erosion process with the void-filling or island-removal process; however, you can run DILATEBIT in succession to do so.

You specify erosion and dilation with negative and positive integers, respectively.

To Do this Result
Dilate (grow) a bitmap by n pixels Enter a positive integer to define the radius n of bits to set around the bits unset currently. Applies the dilation of radius n around the the bits unset currently.
Erode (shrink) a bitmap by n pixels Enter a negative integer to define the radius n of bits to set around the bits unset currently. Applies the erosion of radius n around the the bits unset currently.
Fill voids Enter as the first value the maximum size, in pixels, of areas to fill. Voids containing fewer than the number of pixels of the first specified threshold size will be filled.
Remove islands Enter as the second value the maximum size, in pixels, of islands to remove. Islands containing fewer than the number of pixels of the second specified threshold size will be filled.

The output bitmap layer cannot be the same as the input bitmap; that is, if the output and input file are the same, the value of DBOB and DBIB must differ.

Back to top

Examples

In the following example, a bitmap segment of low values is created by first running the THR algorithm. DILATEBIT is then run to create buffers around the low-value areas.

The isolated areas are removed by an erosion operation (Size: -1), followed by a merging (dilation) of islands that are within 6 pixels of each other (Size: 3), because each island is expanded. A second erosion follows (Size: -2), which results in a one pixel buffer around the merged data of the second operation. On completion of the three operations, voids with fewer than 50 pixels are filled, and islands containing less than 30 pixels are removed.


# Generate a bitmap of the pixels in channel 1 with values between 0 and 0.25
from pci.thr import thr
file = "input.pix"
dbic = [1]
dbob = []
tval = [0,0.25]
comp = "Off"
dbsn = "Low Val"
dbsd = "Bitmap of low values"

thr( file, dbic, dbob, tval, comp, dbsn, dbsd )

from pci.dilatebit import dilatebit
fili = file
dbib = [2]
filo = fili
dbob = []
size = [-1, 3, -2]
sthresh = [50, 30]
dbsd = "Buffered bitmap"

dilatebit(fili, dbib, filo, dbob, size, sthresh, dbsd)
      

In the following example, the bitmap in segment 2 is examined, and voids less than 20 pixels in size and islands less than 40 pixels in size are removed. The result is written to the existing segment 3.

# Remove bitmap voids and islands
from pci.dilatebit import dilatebit
fili = "file_with_bitmap.pix"
dbib = [2]
filo = fili
dbob = [3]
size = []
sthresh = [20, 40]
dbsd = "Bitmap with voids and islands removed"

dilatebit(fili, dbib, filo, dbob, size, sthresh, dbsd)

      

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