stretchacres

Description

stretchacres (originally named after the ACRES array header format in 1990, later updated to OMG1 JHC_header arrays) is an 8-bit raster contrast-stretching, value-replacement, and format-conversion tool. It reads an 8-bit OMG array file (such as a .vert_prof water column vertical profile generated by makeWC, an .8bit bathymetry grid from r4to8bit, or a .mos sidescan mosaic from mos2), stretches pixel Digital Numbers (DNs) between user-specified -low and -high thresholds (or automatically around the image mean via -centre_range), and writes either an updated OMG1 array file or a standard Netpbm .pgm (greyscale) or .ppm (RGB color palette) image.

In the Kongsberg .kmall unraveling workflow (unravel_KMALL_single and unravel_KMALL_2500m_RevHplus_netatt2), stretchacres is used right after makeWC and fillGap to convert the gap-filled water column vertical profile (temp.vert_prof) into a contrast-stretched .pgm image before ImageMagick convert rotates, flops, and labels it as a .vert_prof.gif:

makeWC -maxdepth 2500 -pixel 2.5 -aspect 0.10 -add_heave -other_heave \
    -vert_prof merged/$SUBDIR/$LINE_NUMBER.merged merged/$SUBDIR/$LINE_NUMBER.vert_prof

fillGap -ignore 88 merged/$SUBDIR/$LINE_NUMBER.vert_prof temp.vert_prof

stretchacres \
    -low 120 -high 200 \
    -in temp.vert_prof -pgm -out temp.pgm

convert -rotate 90 -flop temp.pgm temp.ppm
convert -font helvetica -fill blue -pointsize 24 -draw "text 20,995 '$LINE_NUMBER'" \
    temp.ppm merged/$SUBDIR/$LINE_NUMBER.vert_prof.gif

Usage

stretchacres [OPTIONS] -in <infile> -out <outfile>

Common Examples

1. Stretch a water column vertical profile to PGM (standard .kmwcd unravel step):

stretchacres -low 120 -high 200 -in temp.vert_prof -pgm -out temp.pgm

2. Automatic contrast stretch centered $\pm 30$ DN around the mean (ignoring background 255):

stretchacres -centre_range 60 -ignore 255 -in mosaic.mos -pgm -out mosaic.pgm

3. Convert an 8-bit OMG array to a color-mapped PPM image using the OMG LDGO palette:

stretchacres -low 16 -high 250 -ppm -in bathy.8bit -out bathy.ppm

Arguments

Option Description Default
-in <filename> Required. Input 8-bit OMG array file (or raw headerless raster if -xy is specified). None
-out <filename> Required. Output filename (OMG1 array, .pgm, or .ppm). None
-low <DN> Input pixel value (0–255) mapped to the bottom of the output range (-bot). Note: if -low is greater than -high, stretchacres swaps them and automatically enables -invert! 0
-high <DN> Input pixel value (0–255) mapped to the top of the output range (-top). 255
-centre_range <width> Compute the mean of all valid pixels (!= -ignore) in the input file and automatically set low = mean - width/2 and high = mean + width/2. Disabled (width = 60)
-ignore <DN> Pixel value ignored when computing the mean for -centre_range. 255
-bot <DN> Minimum output pixel DN value for stretched pixels. 0
-top <DN> Maximum output pixel DN value for stretched pixels. 255
-mid1 <in_DN> <out_DN> Define a 2-segment piecewise linear stretch where <in_DN> maps to <out_DN>. Disabled
-mid2 <in_DN> <out_DN> Used with -mid1 to define a 3-segment piecewise linear stretch. Disabled
-dBlinear Stretch in linear acoustic power space ($10^{\text{dB}/10}$) rather than logarithmic dB space. Disabled
-invert Invert output greyscale values (255 - val). Disabled
-nozero Clamp stretched non-zero pixels so they never become 0 (sets 0 to 1). Disabled
-no16 Reserve the first 16 colormap indices (0–15) by clamping minimum output values to 16. Disabled
-pgm Write output in standard Netpbm binary greyscale (P5) format instead of an OMG1 JHC_header file. Disabled
-ppm Write output in standard Netpbm binary RGB (P6) format using the OMG LDGO color palette (prime_palettes()). Disabled
-greyX Used with -ppm: outputs a greyscale RGB image while preserving special annotation color indices (YELLOW, RED, GREEN, BLUE, CYAN, MAGENTA, BLACK, WHITE). Disabled
-switch <in_DN> <out_DN> Replace all occurrences of <in_DN> with <out_DN>. Disabled
-swap <low_DN> <high_DN> <out_DN> Replace any pixel value strictly between <low_DN> and <high_DN> with <out_DN>. Disabled
-replace <DN> Fill isolated pixels equal to <DN> using their immediate horizontal or vertical neighbor (j-1, j+1, or prev_row). Disabled
-border <thickness> <color_DN> Draw a border of <thickness> pixels with value <color_DN> around the edges of the image. Disabled
-box <left_x> <right_x> <top_y> <bot_y> Draw a double-lined white/black rectangular box at the specified pixel coordinates. Disabled
-fix <x> <y> <color_DN> Draw a crosshair target marker centered at pixel (x, y) with value <color_DN>. Disabled
-xy <cols> <rows> Treat the input file as a raw headerless byte array of dimensions <cols> x <rows> instead of reading a 1024-byte JHC_header. Disabled
-addhead Used with -xy: prepend a 1024-byte OMG1 JHC_header (or PGM/PPM header) to the output file. Disabled