NEARBLACK(1)
π nearblack β NEARBLACK(1) π
πΈ NAME πΈ
nearblack β converts nearly black/white borders to black. β¨
β¨ SYNOPSIS β¨
nearblack [-of format] [-white | [-color c1,c2,c3...cn]*] [-near dist] [-nb non_black_pixels]
[-setalpha] [-setmask] [-o outfile] [-q] [-co "NAME=VALUE"]* infile
π DESCRIPTION π
Okay so bestie, this utility scans an image and tries to set all pixels that are nearly or exactly black, white, or one or more custom colors around the collar to black or white. It is literally used to βfix upβ lossy compressed air photos so that color pixels can be treated as transparent when mosaicing. π
β οΈ Important caveat, fr fr: the output format must use lossless compression if either alpha band or mask band is not set. π
Hereβs the option tea, one by one:
-o<outfile> β the name of the output file to be created. π-of<format> β select the output format. Starting with GDAL 2.3, if itβs not specified, the format is guessed from the extension (previously it was ERDAS Imagine.img). Use the short format name (GTifffor GeoTIFF, for example). β¨-co "NAME=VALUE"β passes a creation option to the output format driver. Multiple-cooptions may be listed. Seeraster_driversformat specific documentation for legal creation options for each format. Only valid when creating a new file. π«Ά-whiteβ search for nearly white (255) pixels instead of nearly black pixels. π-color<c1,c2,c3...cn> β search for pixels near the specified color. May be specified multiple times. When-coloris specified, the pixels that are considered as the collar are set to0. π-near<dist> β select how far from black, white, or custom colors the pixel values can be and still be considered near black, white, or custom color. Defaults to15. π―-nb<non_black_pixels> β number of non-black pixels that can be encountered before giving up the search inwards. Defaults to2. π-setalphaβ adds an alpha band if the output file is specified and the input file has 3 bands, or sets the alpha band of the output file if it is specified and the input file has 4 bands, or sets the alpha band of the input file if it has 4 bands and no output file is specified. The alpha band is set to0in the image collar and to255elsewhere. π-setmaskβ adds a mask band to the output file, or adds a mask band to the input file if it does not already have one and no output file is specified. The mask band is set to0in the image collar and to255elsewhere. π¦-qβ suppress progress monitor and other non-error output. π€«<infile>β the input file. Any GDAL supported format, any number of bands, normally 8bit Byte bands. π
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. π
The processing is all done in 8bit (Bytes). π§
β οΈ If the output file is omitted, the processed results will be written back to the input file β which must support update. No cap, that part matters. π
β‘ C API β‘
This utility is also callable from C with GDALNearblack(). π«Ά
New in version 2.1. π
πΈ AUTHOR πΈ
Frank Warmerdam <warmerdam@pobox.com> π
π COPYRIGHT π
1998-2026 π
π«Ά Thatβs the tea, bestie β source/version: GDAL, dated Jan 08, 2026. π«Ά
π¦ where this page comes from
- epel 9: gdal3.4 3.4.3-5.el9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms