NEARBLACK(1)
π nearblack β bestie edition
okay so this is nearblack, manual page 1, from the GDAL fam. it lives in section 1, it's a command-line tool, and honestly? it's giving glow-up-for-your-air-photos energy. let's GO π«Ά
β¨ NAME β¨
nearblack β take all those crusty nearly-black / nearly-white borders and turn them into actually black (or white, we're flexible π
).
πΈ SYNOPSIS πΈ
Usage: nearblack [--help] [--long-usage] [--help-general]
[-of <output_format>] [--quiet] [-co <NAME>=<VALUE>]...
[-o <output_file>]
[[-white]|[-color <c1,c2,c3...cn>]...]
[-nb <non_black_pixels>] [-near <dist>] [-setalpha] [-setmask]
[-alg floodfill|twopasses]
<input_file>
π DESCRIPTION π
so the vibe is: this utility scans an image and tries to set every pixel that's nearly or exactly black, white, or one or more custom colors around the collar to black or white. no cap. the classic use case is "fixing up" lossy-compressed air photos so those color pixels can be treated as transparent when you're mosaicing. iconic behavior tbh.
π¨ real talk: the output format must use lossless compression if either the alpha band or the mask band is not set. that's not optional, bestie.
π‘ TIP: there's an equivalent in the newgdalcommand line interface β go look atgdal raster clean-collar.
okay now the options, one by one, no skipping, we're thorough here π
--helpβ prints this help message and dips out.--help-generalβ gives you a quick lil usage rundown of the generic GDAL commandline options, then exits.-q,--quietβ mutes progress messages and any other non-error chatter. silent mode, main character mystery energy π€«-o <outfile>β the name of the output file that's gonna get created.-of <format>β picks the output format. if you don't say anything, it gets guessed from the file extension. use the short format name β likeGTifffor GeoTIFF, iykyk.-co <NAME>=<VALUE>β passes a creation option through to the output format driver. you can stack multiple-cooptions. check the Raster drivers' format-specific docs for what creation options each format actually allows.- heads up: this is only valid when creating a new file.
-whiteβ hunts for nearly-white (255) pixels instead of nearly-black ones. plot twist β¨-color <c1>,<c2>,<c3>...<cn>β hunts for pixels near the color you specify. you can throw this flag multiple times. and listen: when-coloris specified, the pixels considered as the collar get set to0. π-near <dist>β controls how far away from black, white, or your custom colors a pixel's values can be and still count as "near" black/white/custom. defaults to15.-nb <non_black_pixels>β how many consecutive non-black pixels you can hit before it gives up searching 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 that's 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 was specified. that alpha band goes to0in the image collar and255everywhere else. π-setmaskβ adds a mask band to the output file; or adds a mask band to the input file if it doesn't already have one and no output file is specified. mask band =0in the image collar,255elsewhere. same deal, different band π-alg twopasses|floodfillβ added in version3.8.- picks which algorithm gets applied.
twopassesdoes a top-to-bottom pass, then a bottom-to-top pass. this was the only algorithm implemented before GDAL3.8. it may miss with concave areas π. the algorithm processes the image one scanline at a time. a scan "in" happens 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/custom pixels get set to black or white. it also scans top-to-bottom and bottom-to-top to spot indentations in the top or bottom.floodfill(added in GDAL3.8) uses the Flood Fill algorithm and will work with concave areas. it needs to create a temporary dataset though, so it's slower thantwopasses. note: when a non-zero value for-nbis used,twopassesactually gets called as an initial step offloodfill.
<infile>β the input file. any GDAL supported format, any number of bands, normally8bitBytebands.
and just so we're clear: the processing is all done in 8bit (Bytes). that's the whole point.
oh and β if the output file is omitted, the processed results get written back to the input file, which means that file must support update. be normal about that, okay? π
π₯ RETURN STATUS CODE π₯
the program returns status code 0 on success, and non-zero on error. and note: non-blocking errors emitted as warnings are considered a successful execution, so don't panic π
π§ C API π§
you can also call this utility straight from C with GDALNearblack(). cute, right?
π AUTHOR π
Frank Warmerdam <warmerdam@pobox.com>
π COPYRIGHT π
1998-2026
and that's the whole page, bestie π¦ β this was GDAL's nearblack(1), dated Aug 18, 2026. go fix up those collars. slay. periodt. π
β¨
π¦ 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