NEARBLACK(1) | GDAL | NEARBLACK(1) |
nearblack - Convert nearly black/white borders to black.
nearblack [--help] [--help-general] [-of <format>] [-white | [-color <c1>,<c2>,<c3>...<cn>]...] [-near <dist>] [-nb <non_black_pixels>] [-setalpha] [-setmask] [-alg twopasses|floodfill] [-o <outfile>] [-q] [-co <NAME>=<VALUE>]... <infile>
This utility will scan an image and try to set all pixels that are nearly or exactly black, white or one or more custom colors around the collar to black or white. This is often used to "fix up" lossy compressed air photos so that color pixels can be treated as transparent when mosaicing. The output format must use lossless compression if either alpha band or mask band is not set.
Only valid when creating a new file
Selects the algorithm to apply.
twopasses uses a top-to-bottom pass followed by a bottom-to-top pass. This is the only algorithm implemented before GDAL 3.8. It may miss with concave areas. 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.
floodfill (added in GDAL 3.8) uses the Flood Fill algorithm and will work with concave areas. It requires creating a temporary dataset and is slower than twopasses. When a non-zero value for -nb is used, twopasses is actually called as an initial step of floodfill.
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.
This utility is also callable from C with GDALNearblack().
New in version 2.1.
Frank Warmerdam <warmerdam@pobox.com>
1998-2024
February 8, 2024 |