GDAL-RASTER-CLEAN-COLLAR(1)

πŸ’– gdal-raster-clean-collar πŸ’–

okay bestie, buckle up, because this is the gdal-raster-clean-collar manual page, straight out of the GDAL manual collection. She's here to clean the collar of a raster dataset and remove all that noise, and honestly? she ate. ✨

πŸŽ€ Added in version 3.11. so she's a fresh face, iykyk.

✨ SYNOPSIS ✨

Usage: gdal raster clean-collar [OPTIONS] <INPUT> [<OUTPUT>]

Clean the collar of a raster dataset, removing noise.

Positional arguments:
  -i, --input <INPUT>                                  Input raster dataset [required]
  -o, --output <OUTPUT>                                Output raster dataset

Common Options:
  -h, --help                                           Display help message and exit
  --json-usage                                         Display usage as JSON document and exit
  --config <KEY>=<VALUE>                               Configuration option [may be repeated]
  -q, --quiet                                          Quiet mode (no progress bar or warning message) [not available in pipelines]

Options:
  -f, --of, --format, --output-format <OUTPUT-FORMAT>  Output format
  --co, --creation-option <KEY>=<VALUE>                Creation option [may be repeated]
  --overwrite                                          Whether overwriting existing output dataset is allowed
  --update                                             Whether to open existing dataset in update mode
  --color <COLOR>                                      Transparent color(s): tuple of integer (like 'r,g,b'), 'black', 'white' (default: black) [may be repeated]
  --color-threshold <COLOR-THRESHOLD>                  Select how far from specified transparent colors the pixel values are considered transparent. (default: 15)
  --pixel-distance <PIXEL-DISTANCE>                    Number of consecutive transparent pixels that can be encountered before the giving up search inwards. (default: 2)
  --add-alpha                                          Adds an alpha band to the output dataset.
                                                       Mutually exclusive with --add-mask
  --add-mask                                           Adds a mask band to the output dataset.
                                                       Mutually exclusive with --add-alpha
  --algorithm <ALGORITHM>                              Algorithm to apply. ALGORITHM=floodfill|twopasses (default: floodfill)

Advanced Options:
  --oo, --open-option <KEY>=<VALUE>                    Open options [may be repeated]
  --if, --input-format <INPUT-FORMAT>                  Input formats [may be repeated]

🌸 DESCRIPTION 🌸

so like. gdal raster clean-collar scans an (8-bit) image and sets all the pixels that are nearly or exactly black (that's the default btw), white, or one or more custom colors around the collar β€” and it flips them to black or white. that's it. that's the whole vibe check. πŸ’…

and why would you even want that? because it's often used to "fix up" lossy compressed air photos so that color pixels can be treated as transparent when mosaicing. iconic behavior honestly.

⚠️ real talk: the output format must use lossless compression if either the alpha band or the mask band is not set. no exceptions, bestie, the vibes demand losslessness.

πŸŽ€ PROGRAM-SPECIFIC OPTIONS πŸŽ€

  • --add-alpha β€” adds an alpha band to the output file. the alpha band is 0 in the image collar and 255 everywhere else. this one is mutually exclusive with --add-mask β€” pick one, you cannot have both, that's the rule 🫢
  • --add-mask β€” adds a mask band to the output file. the mask band is 0 in the image collar and 255 everywhere else (yes same energy as alpha). mutually exclusive with --add-alpha, same deal.
  • --algorithm floodfill|twopasses β€” picks which algorithm to apply. two whole options, let's get into it:
    • twopasses does a top-to-bottom pass followed by a bottom-to-top pass. she may miss with concave areas (🚩 noted). the algorithm processes the image one scanline at a time. a scan "in" is done from either end, setting pixels to black or white until at least "non_black_pixels" pixels that are more than "dist" gray levels away from black, white or custom colors have been encountered β€” at which point the scan stops. the nearly black, white or custom color pixels are set to black or white. the algorithm also scans from top to bottom and from bottom to top to identify indentations in the top or bottom. thorough queen πŸ’…
    • floodfill (the default) uses the Flood Fill algorithm and will work with concave areas πŸ¦‹. downside? it requires creating a temporary dataset and it's slower than twopasses. and when a non-zero value for --pixel-distance is used, twopasses is actually called as an initial step of floodfill. teamwork!
  • --color <c1>,<c2>,<c3>...<cn>|black|white β€” search for pixels near the specified color. may be specified multiple times. when this option is specified, the pixels that are considered as the collar are set to 0, unless only white is specified, in which case there they are set to 255. (white stays winning, apparently πŸ‘‘)
  • --color-threshold <val> β€” select how far from black, white or custom colors the pixel values can be and still considered near black, white, or custom color. defaults to 15.
  • --pixel-distance <val> β€” number of consecutive transparent pixels that can be encountered before the giving up search inwards. said otherwise (bestie translation incoming): the collar will be extended by this number of pixels. defaults to 2.

⭐ STANDARD OPTIONS ⭐

  • --co, --creation-option <NAME>=<VALUE> β€” many formats have one or more optional creation options that can be used to control particulars about the file created. for instance, the GeoTIFF driver supports creation options to control compression, and whether the file should be tiled. πŸŽ€

may be repeated.

the creation options available vary by format driver, and some simple formats have no creation options at all. a list of options supported for a format can be listed with the --formats command line option, but the documentation for the format is the definitive source of information on driver creation options. see Raster drivers format specific documentation for legal creation options for each format. (yes, read the docs, she's not playing.)

  • -f, --of, --format, --output-format <OUTPUT-FORMAT> β€” which output raster format to use. allowed values may be given by:
gdal --formats | grep raster | grep + | sort
  • --overwrite β€” allow the program to overwrite an existing target file or dataset. otherwise, by default, gdal errors out if the target file or dataset already exists. she's protective of your files, lowkey 🫢
  • --update β€” if only an input dataset is specified, ask for it to be opened in update mode. if an output dataset is specified, ask for it to be opened in update mode (this implies that it already exists).
⚠️ heads up: updating an existing dataset may lead to file size increase if the dataset is compressed, and/or quality loss if lossy compression is used. proceed with intention, bestie.

πŸ”₯ RETURN STATUS CODE πŸ”₯

the program returns status code 0 in case of success, and non-zero in case of error. (and yes β€” non-blocking errors emitted as warnings are considered as a successful execution. soft launch failure, we move.)


🌈 EXAMPLES 🌈

Example 1: Edit in place a dataset using the default black color as the color of the collar

$ gdal raster clean-collar --update my.tif

Example 2: Create a new dataset, using black or white as the color of the collar, considering values in the [0,5] range as being considered black, and values in the [250,255] range to be white. It also adds an alpha band to the output dataset.

$ gdal raster clean-collar --add-alpha --color=black --color=white --color-threshold=5 in.tif out.tif

πŸ’œ AUTHOR πŸ’œ

Even Rouault <even.rouault@spatialys.com>

1998-2026


okay that's the whole page bestie, go forth and clean those collars πŸ’…βœ¨

πŸ¦‹ sign-off from the GDAL-RASTER-CLEAN-COLLAR(1) manual page, dated Aug 18, 2026 β€” thanks for reading, mwah 🫢
πŸ“¦ where this page comes from