r4to16bit
Overview
r4to16bit linearly scales an OMG JHC_header 32-bit floating-point (.r4) grid (data_type == 3) into a 16-bit unsigned integer array (unsigned short, dynamic range 0..65535) preceded by a 1024-byte JHC_header.
Syntax & CLI Options
r4to16bit [-low <min_val>] [-high <max_val>] [-nozero] <floatfile> <16bitfile>
| Option | Description | Default |
|---|---|---|
<floatfile> | Required. Input 32-bit float JHC_header file (data_type == 3). | None |
<16bitfile> | Required. Output 16-bit unsigned short JHC_header file. | None |
-low <value> | Minimum floating-point value mapped to 0 (or 1 if -nozero is set). If both -low and -high are 0, scans the input file for the actual min and max. | 0.0 (auto-detect) |
-high <value> | Maximum floating-point value mapped to 65535. | 0.0 (auto-detect) |
-nozero | Clamp valid non-zero input floats that scale to 0 up to 1, reserving 0 strictly for nodata (*p == 0.0) pixels. | Disabled |
How It Works
- Header Reading & Range Detection:
- Reads the
JHC_headerfrom<floatfile>and verifiesJHChead.data_type == 3. - If
-lowand-highare both0, scans all non-zero pixels (*p != 0.0) in<floatfile>to determinelow_limitandhigh_limit. - Stores
low_limitandhigh_limitinJHChead.min_valueandJHChead.max_value, setsJHChead.data_type = 1, and writes the 1024-byte header to<16bitfile>.
- Reads the
- 16-Bit Quantization:
- For each pixel
*p:- If
*p == 0.0, outputs0. - Otherwise, computes: \(\text{temp} = \frac{(\text{*p} - \text{low\_limit}) \times 65535}{\text{high\_limit} - \text{low\_limit}}\) clamps
tempto[0, 65535](or[1, 65535]if-nozerois set), and writesdxunsigned shortvalues per row.
- If
- For each pixel
Examples
Scale a bathymetric .r4 grid spanning -3500 m to 0 m into 16-bit unsigned integers, reserving 0 for nodata:
r4to16bit -low -3500 -high 0 -nozero deep_survey.r4 deep_survey.16bit