TIFF SampleFormat: Distinguish Integer and Floating-Point Drone Raster Values
Read BitsPerSample together with SampleFormat and byte-order context before interpreting a numerical TIFF or GeoTIFF delivery; test the distinction on constructed bytes.

Identify the numerical representation of the delivered band
A raster value reported by a custom reader can be very different from the value shown by a geospatial application even when both use the same bytes. Before treating the disagreement as a changed drone observation, identify the sample representation of the accepted raster. In a NiVO mapping handoff, the file extension and bit width are only part of that description. This tutorial distinguishes unsigned integer, signed integer and floating-point interpretations through constructed raw samples. It does not open a real TIFF, decode compressed imagery or establish the meaning of a particular delivered band.
Record the source revision, selected image directory, band, producing application and receiving task. A visual image and a numerical surface can use the same container family while carrying different sample types and meanings. Preserve the original file and the report from the receiving tool before experimenting with another interpretation. If the data type is uncertain, retain that uncertainty rather than selecting the interpretation that produces familiar values. A plausible range can help frame an investigation, but it cannot establish which representation was actually declared by the source.
Read sample format together with width and byte order
LibTIFF defines SampleFormat values for unsigned integer, signed integer and IEEE floating-point data, alongside other representations. Its tag-reading documentation ties returned tag values to the current image directory and requires checking whether retrieval succeeded. Keep the directory identity and actual tag-reading result with the interpretation. A report should distinguish a tag explicitly found from a value supplied through a documented defaulting API. This tutorial requires an explicit sample-format argument and does not infer what a missing tag in an actual file would mean.
GDAL documents separate integer and floating-point band types for its GeoTIFF driver. Those distinctions should remain visible when comparing a library-level sample description with an application-level band type. Width, signedness, byte order and numerical format are related inputs, not interchangeable labels. Container addressing is another question: choosing BigTIFF does not itself change the type of a sample. Likewise, compression and image organization require a suitable decoder before raw sample interpretation. Do not pass arbitrary file bytes to the teaching function as though a TIFF header were a sequence of already decoded band values.

Product context only; this photograph does not depict the constructed examples in this article.
Trace the same bytes through two explicit interpretations
Consider the constructed two-byte value ff ff in an explicitly little-endian sample. With a sixteen-bit unsigned interpretation it yields sixty-five thousand five hundred thirty-five. With a sixteen-bit signed interpretation it yields negative one. The bytes have not changed; only the declared interpretation has changed. Neither result establishes a valid observation, a missing-value marker or a physical unit. In a separate four-byte example, the hexadecimal bytes 00 00 80 3f yield floating-point one under the selected little-endian float interpretation and a very different unsigned integer under another interpretation.
The Python function below supports a deliberately small set of width and sample-format combinations. It requires an exact byte count and an explicit byte-order name, then uses a standard-size struct format. The examples work on already available raw sample bytes in memory. They do not implement TIFF directory parsing, strip or tile decompression, predictor reversal, band extraction or a georeferencing model. Unsupported representations stop with an error rather than being forced into a convenient integer type. A stop identifies the recipe boundary and is not a declaration that every other TIFF representation is invalid.
import struct
def interpret_sample(raw, bits, sample_format, byte_order):
if type(bits) is not int or type(sample_format) is not int:
raise ValueError("explicit integer width and sample format required")
if byte_order not in ("little", "big"):
raise ValueError("explicit little or big byte order required")
formats = {(16, 1): "H", (16, 2): "h",
(32, 1): "I", (32, 2): "i", (32, 3): "f"}
code = formats.get((bits, sample_format))
if code is None:
raise ValueError("outside this small sample profile")
if not isinstance(raw, (bytes, bytearray)) or len(raw) != bits // 8:
raise ValueError("expected exactly one decoded raw sample")
prefix = "<" if byte_order == "little" else ">"
return struct.unpack(prefix + code, raw)[0]
# Constructed raw samples; these are not TIFF file contents.
raw16 = bytes.fromhex("ff ff")
print(interpret_sample(raw16, 16, 1, "little"))
print(interpret_sample(raw16, 16, 2, "little"))
raw32 = bytes.fromhex("00 00 80 3f")
print(interpret_sample(raw32, 32, 3, "little"))
print(interpret_sample(raw32, 32, 1, "little"))Separate interpretation from conversion and validity
Reinterpreting the same bytes under a different type is not the same operation as numerically converting a correctly decoded value into a new storage type. A conversion begins with an established source value and an explicit destination policy. A reinterpretation changes how the bit pattern is read. Keep those operations distinguishable in a troubleshooting record. Do not edit a sample-format declaration merely because another interpretation makes a preview look better. Obtain the producing workflow and intended representation before treating the discrepancy as something that should be repaired in the received raster.
A decoded value also needs its validity and measurement context. A negative number can be meaningful in one band and a reserved indicator in another. A floating-point result may require checks for nonfinite values or a project-specific missing-data rule. The small function does not reject every unusual numerical value or assign a physical meaning to it. Keep masks, missing-data declarations, scale and offset, units and relevant band metadata available for the receiving analysis. Those checks remain separate from establishing how one raw sample was decoded.
Compare actual reader evidence before changing a raster
For a real delivery, use an appropriate raster library to identify the selected image and decode its samples. Compare its reported band type and relevant metadata with the producing specification and the custom reader assumptions. Record the software version, selected directory and any warnings. This tutorial does not invoke GDAL or LibTIFF against an actual file. Its memory-only examples explain a representation distinction that can guide the investigation, while the actual decoding and acceptance work still needs the intended dataset and receiving environment.
If two tools disagree, first establish that they read the same directory, band and source revision. Then inspect the representation and any deliberate conversion performed by either workflow. A mismatch in a numerical table should not be hidden by rescaling the displayed colors. Conversely, a different display stretch is not by itself evidence that sample values changed. The product photograph provides context only and does not depict the constructed bytes, an elevation model or a measured accuracy result. Keep the source discrepancy identifiable so the producer can investigate it without losing the original evidence.
Deliver a sample interpretation contract
A useful raster handoff records the file revision, selected directory and band, decoded type, width, sample-format evidence, byte-order context and intended numerical meaning. Distinguish explicit declarations from defaults and report any unsupported representation. Include the actual library used to decode the raster and retain a reproducible comparison where values differed. Another analyst should be able to understand why a sample was read as signed, unsigned or floating point without guessing from its filename, apparent range or rendered color. Preserve any corrected derivative as a new revision.
For NiVO numerical raster discussions, this gives a concrete starting point for resolving an unexpected value. The tutorial separates the byte pattern, its declared representation, a later conversion and the project meaning of the decoded result. It complements container-size and raster metadata reviews without replacing full decoding, validity or spatial acceptance checks. Establish the representation first, verify the actual receiving values second and support the intended analysis with its own evidence. A correct sample interpretation is necessary context for a useful raster, but it is not an independent guarantee of survey quality or analytical suitability.



