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:twopassesdoes 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 thantwopasses. and when a non-zero value for--pixel-distanceis used,twopassesis actually called as an initial step offloodfill. 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 to0, unless only white is specified, in which case there they are set to255. (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 to15.--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 to2.
β 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,gdalerrors 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>
π COPYRIGHT π
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
- alpine 3.24: gdal-doc 3.13.3-r0 Β· MIT
- arch rolling: gdal 3.13.3-6 Β· MIT
- ubuntu stonking: gdal-bin 3.13.3+dfsg-1ubuntu4 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms