Computer vision
Pixels, Color, and Dynamic Range
Learn how sampling, channels, bit depth, color encoding, and normalization shape the numerical evidence seen by a vision system.
By the end you can
- Describe pixels as samples with spatial, spectral, and numerical conventions
- Distinguish resolution, bit depth, channel count, and color space
- Recognize how clipping, quantization, and normalization can remove useful evidence
- Trace shape and value ranges through an image preprocessing pipeline
Example
The profile is normative, and the numbers on their own are not
A pixel triplet does not carry its own meaning. What the three numbers stand for is fixed by the profile attached to the file. In a browser that is not a convention but a requirement. Take a JPEG tagged ITU-R BT.2020, shown on a Display P3 screen. CSS Color Module Level 4 rules on that exact case: “It must not treat the ITU Rec BT.2020 values as if they were Display P3 values, which would produce incorrect colors.” The image has to be converted into the display's space first.
That is the rule a pipeline breaks when it drops the profile on load. Nothing errors, because the fallback is specified too: “For compatibility, colors specified in HTML, and untagged images must be treated as being in the sRGB color space ([SRGB]) unless otherwise specified”. The loader keeps working. It simply reads wide-gamut numbers as sRGB numbers, and the two spaces are not close — the W3C gamut-volume table puts rec2020 at 2.042 million Lab units against display-p3's 1.233 and sRGB's 0.820. Nothing was lost in transit. The numbers were read in the wrong language.
- Tagged file: CSS Color Module Level 4 requires a JPEG carrying an ITU-R BT.2020 profile to be converted into the display's colour space before it is shown, not read as it stands.
- Untagged file: sRGB is the default — “For compatibility, colors specified in HTML, and untagged images must be treated as being in the sRGB color space ([SRGB]) unless otherwise specified”. A dropped profile therefore fails silently.
- Distance between the two spaces: ITU-R BT.2020-2 places the red primary at x=0.708, y=0.292, green at 0.170, 0.797 and blue at 0.131, 0.046, with reference white D65 at 0.3127, 0.3290. W3C measures that gamut at 2.042 million Lab units against sRGB's 0.820.
- Same triplet, different light: BT.2020-2 derives luma with the coefficients 0.2627, 0.6780 and 0.0593, where BT.709 uses 0.2126, 0.7152 and 0.0722. Identical stored values imply a different luminance depending on which document applies.
- Lesson: a tensor can keep the same dimensions, the same channel order and the same integer range while changing its physical and perceptual meaning.
Visual
An image tensor carries more than height and width
Four properties have to be tracked together when interpreting image values. Each one is something a real specification writes down. None of them can be read off the array.
Spatial grid: rows and columns sample the projected scene at finite locations, and the spacing can be mandated — the FBI's Electronic Biometric Transmission Specification fixes fingerprint scanning at 500 or 1,000 ppi within ±1%.
Channels: values may represent red, green, blue, alpha, depth, infrared or another measured band. Their count says nothing about their resolution. Sentinel-2's Multi-Spectral Instrument carries 13 bands sampled at three different ground resolutions.
Numeric encoding: integers or floating-point values use a bit depth, scale, offset and valid range, and the container need not match the measurement. ESA acquires at 12 bits and ships 16-bit integers.
Colour interpretation: transfer functions, primaries, white points and profiles determine perceived colour, and CSS Color Module Level 4 makes the profile binding on the renderer.
Drop any one of the four and the array still loads.
Spatial grid
Rows and columns sample the projected scene at finite locations.
Channels
Values may represent red, green, blue, alpha, depth, infrared, or another measured band.
Numeric encoding
Integers or floating-point values use a bit depth, scale, offset, and valid range.
Color interpretation
Transfer functions, primaries, white points, and profiles determine perceived color.
Resolution is a sampling choice, not a synonym for detail
An image with 4000 by 3000 pixels contains twelve million samples. It does not contain twelve million independent pieces of scene information. Lens blur, motion, demosaicing, compression and sensor noise all reduce effective detail. A smaller image can preserve the task signal instead, as long as the objects stay large enough after resizing.
Where the stakes are high, the choice is made explicitly and written into a specification. The FBI's Electronic Biometric Transmission Specification states the requirement for a fingerprint scanner in a single sentence: “The scanner's final output resolution in both sensor detector row and column directions shall be in the range: (R–0.01R) to (R+0.01R) and shall be gray-level quantized to eight bits per pixel (256 gray-levels).” R is 500 or 1,000 ppi, so the tolerance is ±1%. Field-level rules narrow Type-4 records further, to 495–505 ppi.
NIST's compression guidance for 1000 ppi friction ridge imagery records the installed base: “The criminal justice community has traditionally exchanged and stored fingerprint imagery data at 500 pixels per inch (ppi) or 19.7 pixels per millimeter (ppmm)”, with WSQ as the compression standard at that resolution. For 1000 ppi imagery it specifies JPEG 2000 at “Bit depth Ssiz = 7 (corresponding to 8-bit Gray Scale)”, with a final ratio of 10:1 for rolled, flat, slap and palm impressions. Latent imagery is compressed losslessly instead, at 1:1. Two separate axes, two separate numbers, both fixed on purpose.
The sampling question does not stop at the file. Shift an image down by one pixel and a trained network can change its answer. Azulay and Weiss measured how often, testing six ImageNet networks — VGG16, ResNet50 and InceptionResNetV2 from Keras, VGG16, ResNet50 and DenseNet121 from PyTorch — on 1,000 images under four one-pixel perturbation protocols. Their 2019 paper reports it plainly: “We show that the chance that a CNN output on a randomly chosen image will change after translating downward by a single pixel can be as high as 30%.” That 30% ceiling belongs to the Keras models; the PyTorch DenseNet121 tops out at 0.19.
Their diagnosis is a sampling one: “The convolutional architecture ignores the classical sampling theorem, so that aliasing effects make the output not invariant”. Richard Zhang named the same culprit the same year — “Commonly used downsampling methods, such as max-pooling, strided-convolution, and average-pooling, ignore the sampling theorem” — and showed that the repair pays. Inserting a low-pass filter before those stages cut ResNet-50's mean flip rate on ImageNet-P from 7.92 to 6.90, and its mean corruption error on ImageNet-C from 60.6 to 58.1, with a Bin-5 filter. ImageNet accuracy improved as well. Neither paper is describing a failure of the model. Both are describing a failure of the grid underneath it.
Count pixels, then ask what spatial frequencies and object sizes they actually preserve.
Case
Three times the pixels bought 2.7 accuracy points
Roughly three times as many pixels bought 2.7 accuracy points. Touvron and three colleagues put that number on the gap between resolution and accuracy in 2019, in an abstract reporting “77.1% top-1 accuracy on ImageNet with a ResNet-50 trained on 128x128 images, and 79.8% with one trained” at 224x224.
Their actual subject is not capacity but sampling. The problem they set out to fix is “a significant discrepancy between the … size of the objects seen by the classifier at train and test time” — a mismatch between the object sizes a classifier is trained on and the ones it is asked to recognise. That is a question about the sampling grid long before it is a question about the network.
Figure
Comparison
RGB, grayscale, depth, and multispectral arrays
Channel count alone does not reveal how values should be processed. An RGB photograph is typically H × W × 3 and encodes a display-oriented view of visible light; its characteristic failure is a channel-order mismatch, and its usual transform is colour normalisation. A grayscale image is H × W or H × W × 1. It records intensity under a specific acquisition process — an X-ray, a document scan — with the discarded colour signal as the risk and contrast adjustment as the usual transform. A depth map estimates distance or disparity per pixel, in metres or inverse depth. It carries invalid and missing values, so it is range-masked before use. A multispectral image samples distinct wavelength ranges in several bands, at possibly different resolutions. Its risk is precisely that it looks like display RGB. What it needs is radiometric calibration, not colour normalisation.
Sentinel-2 shows how far the last case is from a three-channel photograph. ESA describes “the optical Multi-Spectral Instrument (MSI) that samples 13 spectral bands: four bands at 10 m, six bands at 20 m and three bands at 60 m spatial resolution”. NASA Earthdata publishes the identical split: “Sentinel-2 MSI samples 13 spectral bands at different spatial resolutions: four bands at 10 meter resolution, six bands at 20 meter resolution, and three bands at 60 meter resolution.” There is no single H and W for the scene. Three of them coexist inside one product.
The numeric axis is separate again, and the container lies about it. ESA states that “The radiometric resolution of the MSI instrument is 12 bit (1), enabling the image to be acquired over a range of 0 to 4095 potential light intensity values”, and the footnote spells out what happens next: “The Sentinel-2 instrument acquires measurements at 12 bits. These measurements are converted to reflectance and stored as 16-bit integers in the S2 product.” The instrument measures 12 bits. The container is 16. A pipeline that reads the dtype and trusts it has invented precision the instrument never measured.
RGB photograph
Three color channels encode a display-oriented view of visible light.
- Typical shape: H × W × 3
- Risk: channel-order mismatch
- Common transform: color normalization
- Use case: consumer imagery
Grayscale image
One channel records intensity under a specific acquisition process.
- Typical shape: H × W or H × W × 1
- Risk: discarded color signal
- Common transform: contrast adjustment
- Use case: X-ray or document scan
Depth map
Each pixel estimates distance or disparity rather than brightness.
- Typical units: metres or inverse depth
- Risk: invalid and missing values
- Common transform: range masking
- Use case: robotics and 3D
Multispectral image
Several bands sample distinct wavelength ranges at possibly different resolutions.
- Typical issue: band alignment
- Risk: treating bands like display RGB
- Common transform: radiometric calibration
- Use case: remote sensing
Key idea
Eight-bit display values can hide a sixteen-bit measurement
Converting a high-dynamic-range sensor image to 8-bit values can collapse subtle differences. A windowing rule that looks acceptable on a monitor may remove the evidence needed for detection or diagnosis. In medical imaging that rule is not informal. It is two attributes in the standard.
DICOM defines them in its VOI LUT module: “Window Center (0028,1050) and Window Width (0028,1051) specify a linear conversion from stored pixel values (after any Modality LUT or Rescale Slope and Intercept specified in the IOD have been applied) to values to be displayed.” The default LINEAR form clips at both ends — “if (x <= c - 0.5 - (w-1)/2), then y = y min; else if (x > c - 0.5 + (w-1)/2), then y = y max”. The standard's own worked example, c=2048 with w=4096, maps stored inputs 0–4095 onto an output range of 0 to 255. Everything outside the window is gone, identically, for every voxel that fell there.
The choice of c and w is therefore a modelling decision, and it is measurable. A 2018 study trained Inception-v3 on 904 head CTs and 515 abdominopelvic CTs. From full-range Hounsfield values the model reached AUC 0.923 for intracranial haemorrhage and 0.800 for urinary stone. With the standard brain window (WL=50, WW=100) and bone window (WL=300, WW=1500), the same architecture on the same scans reached 0.963 and 0.917. With learned window settings, 0.976 and 0.972. The scans did not change. Only the mapping into eight bits did.
So the conversion has to be documented, with units, clipping limits and any nonlinear mapping. Otherwise later teams cannot reproduce what the model actually saw.
The encoding is not linear either, and that matters before any bit-depth choice is made. ITU-R BT.709 sets the luma coefficients at 0.2126 for red, 0.7152 for green and 0.0722 for blue. W3C uses the same three numbers for sRGB relative luminance, and first undoes the transfer function: values at or below 0.04045 are divided by 12.92, and the rest are raised to the power 2.4. So an 8-bit value of 128 is not half the light of 255, and averaging three channels is not the brightness a viewer sees.
A window setting is not a viewing preference: 0.923 against 0.976 on the same scans.
Analogy
Buckets placed across a rain field
Buckets arranged on a field measure rainfall. More buckets provide denser samples. Larger measuring marks provide finer intensity resolution.
A bucket holds only what falls into it, while pixels also mix light through optics and sensor electronics. Spatial sampling and numeric precision stay separate questions. That is why the FBI specification has to state both of them in one sentence: the grid at 500 or 1,000 ppi within ±1%, and the quantisation at eight bits per pixel. Neither number can be recovered from the other. Sentinel-2 makes the same point from the other side — 10, 20 and 60 m ground sampling across 13 bands, and 12 bits of radiometry, are four numbers that vary independently.
Spatial resolution and bit depth answer different measurement questions.
Steps
Create a pixel-value ledger
Record these decisions for every image source before training. The source encoding: file format, profile, channel order, bit depth, compression. The physical meaning of each channel, and its units. The invalid ranges: missing values, saturation, clipping, padding, sensor sentinels. The transformations in order, from resize and crop through colour conversion, scaling and normalisation. And a verification step using known images and exact tensor checks, so that a silent pipeline change is detected rather than absorbed.
One published dataset shows what a finished ledger looks like. MIMIC-CXR distributes chest radiographs in DICOM — “A total of 377,110 images are available in the dataset”, from 227,835 imaging studies of 65,379 patients. The derived 8-bit release, MIMIC-CXR-JPG v2.1.0, reduces exactly those images to JPG, and writes down how: “Pixel values were normalized to the range [0, 255] by subtracting the lowest value in the image, dividing by the highest value in the shifted image, truncating values, and converting the result to an unsigned integer.” The remaining steps are equally explicit. The image is inverted according to the DICOM PhotometricInterpretation field, histogram-equalised with OpenCV, then encoded as JPG at quality factor 95.
Every step in that chain is lossy. None of them is a secret. That is the difference a ledger makes. Two groups training on MIMIC-CXR-JPG are training on the same numbers, and anyone comparing a result on the JPG release against a result on the DICOM originals knows exactly which four operations separate them.
1. Record source encoding
Capture file format, profile, channel order, bit depth, and compression.
2. Define physical meaning
State what each channel measures and which units apply.
3. Mark invalid ranges
Document missing values, saturation, clipping, padding, and sensor sentinels.
4. Specify transformations
List resize, crop, color conversion, scaling, and normalization in order.
5. Verify with fixtures
Use known images and exact tensor checks to detect silent pipeline changes.
Normalization changes optimization, not the scene
Subtracting a mean and dividing by a scale can place channels in a numerically convenient range. It does not correct mislabeled colour profiles, saturation or lost spatial detail. And the constants are not universal. Two mainstream libraries expect incompatible encodings of the same H × W × 3 array.
torchvision documents its pretrained ResNet-50 weights this way: “Finally the values are first rescaled to [0.0, 1.0] and then normalized using mean=[0.485, 0.456, 0.406] and std=[0.229, 0.224, 0.225]”. It lists acc@1 76.13 for IMAGENET1K_V1 and 80.858 for the V2 recipe, on the identical 25,557,032-parameter architecture. Keras' default preprocessing, the mode named “caffe”, takes “values in the range [0, 255]” and does something else entirely: “The images are converted from RGB to BGR, then each color channel is zero-centered with respect to the ImageNet dataset, without scaling.” The constants it subtracts are [103.939, 116.779, 123.68]. Its other two modes differ again — “torch” divides by 255 and applies the mean [0.485, 0.456, 0.406] and std [0.229, 0.224, 0.225], and “tf” divides by 127.5 and subtracts 1.
Feed a [0, 1] tensor to the caffe path and nothing raises. The network receives an image roughly 255 times too dark, with its channels reversed, and reports a confident wrong class. So statistics must be computed on the appropriate training boundary, and that boundary belongs to the weights as much as to the dataset. Reusing values from an unrelated domain may be acceptable for a pretrained backbone, but the decision should be tested rather than assumed.
Numerical conditioning cannot restore information removed earlier in the pipeline.
Key takeaways
- A pixel is a sampled measurement whose meaning depends on channel, scale, unit and encoding — Sentinel-2 acquires at 12 bits and stores 16-bit integers, so the container is not the measurement.
- Spatial dimensions and bit depth are separate decisions, stated separately: the FBI specification fixes 500 or 1,000 ppi within ±1% and eight bits per pixel in the same requirement.
- Colour profiles and transfer functions change the apparent evidence without changing tensor shape; CSS Color Module Level 4 makes a tagged image's conversion mandatory and every untagged image sRGB.
- Clipping and quantization remove task-relevant information permanently: a DICOM window sends everything past c−0.5±(w−1)/2 to the endpoints, and full-range Hounsfield input scored AUC 0.923 against 0.976 for a tuned window.
- Downsampling that ignores the sampling theorem is measurable: a one-pixel downward shift can change up to 30% of a CNN's predictions, and low-pass filtering cut ResNet-50's mean flip rate from 7.92 to 6.90.
- A pixel-value ledger makes pipelines reproducible: MIMIC-CXR-JPG v2.1.0 publishes its normalisation, inversion, equalisation and JPG quality factor 95 for all 377,110 images.