C07 · Change and measure
Brightness, histograms and contrast
A curve changes values, a histogram counts them, and local statistics add neighbourhood information.
Background if needed
Theory
One input, one output
Offset changes all levels; scaling around a pivot changes contrast. A negative maps x to 1−x. Log, power and piecewise-linear curves redistribute the range differently. Tone gamma is a chosen edit, not sRGB encoding.
A flat curve segment merges different inputs into one output. The inspector shows the pre-clipped value, revealing where distinctions are lost. Darkening white after clipping cannot recover highlight texture.
One curve for every point
The upper half is a full gradient, the lower half a partial range. Change one parameter and find where different inputs collapse to black or white.
Exact values are in the point inspector
Grayscale 0…1: black to white.
- Power
- Contrast and offset
- Clamp to [0, 1]
Exact values are in the point inspector
Grayscale 0…1: black to white.
Inspect the selected point
What the plot shows
The curve tells what every input level becomes. The diagonal means no edit; flat sections at 0 and 1 show differences lost to clipping.
- Curve
- No edit
- This pixel: 0.6452; 0.6452
Contrast expands differences; clipping destroys them. Brightening cannot recover clipped information.
Parameters and details
Power tone adjustment, contrast around 0.5 and offset run in that order, then clip to [0,1]. This is a deliberate numerical adjustment, not sRGB encoding. Clipping can map different inputs to the same output, losing invertibility.
Select an image point. Arrows move it; Home and End reach row edges. Viewing does not change the calculation.
Changing the example requires JavaScript and Canvas. Computed images remain available above.
Counting without positions
Split values into bins and count pixels. Dividing by the total gives a distribution; cumulative sums form the CDF. Permuting pixels preserves the histogram while potentially changing the image completely.
Select a dark pixel. On the first graph find its bin and add every column through that bin; divide by the sample count. That fraction is the new brightness on the right and the point's height on the second graph. A brighter pixel accumulates more bins. Local mode uses only the outlined window, so identical inputs at different locations can produce different outputs.
Global equalization maps values through the CDF. Range stretching uses selected endpoints; histogram matching targets another distribution. None proves recovery of scene-correct light.
Local is not always better
Under uneven illumination a single global mapping can struggle. Local equalization uses nearby statistics. Histogram count clipping reduces excessive amplification of frequent values and noise.
Tiled CLAHE interpolates neighbouring tile mappings to avoid a grid. Our live variant is explicitly labelled sliding-window equalization, not CLAHE. Independent R/G/B curves may shift hue; colour photos need a considered lightness channel and space.
Contrast from a value distribution
Compare global and local equalization. Change the local histogram limit and watch the faint pattern and edge.
Exact values are in the point inspector
Grayscale 0…1: black to white.
- Find the selected brightness bin
- Add counts through this bin
- Cumulative fraction is the new brightness
Exact values are in the point inspector
Grayscale 0…1: black to white.
Inspect the selected point
What the plot shows
Horizontal position is brightness; height is the pixel count in each of 16 bins. Move the selected point: the local window and its statistics move together.
- Counts
- Selected input: 0.2483
Step height is the fraction of samples no brighter than the selected bin. It becomes the selected pixel's output brightness. The marker connects the input, cumulative fraction and result on the right. Open the count graph to inspect the counts that produce this cumulative fraction.
- CDF
- This pixel: 0.2483; 0.375
Histograms omit coordinates. Local methods reveal faint changes but can amplify noise.
Parameters and details
Global equalization uses the CDF of 16 bins. Local mode uses a 7 × 7 window, clips counts and redistributes excess uniformly; this is contrast-limited sliding-window equalization, not tiled CLAHE with interpolation. It can amplify noise and change relative brightness between regions.
Select an image point. Arrows move it; Home and End reach row edges. Viewing does not change the calculation.
Changing the example requires JavaScript and Canvas. Computed images remain available above.
Practice
Test the idea under another condition. Follow the task above the images; point inspection helps explain the result. This exploration is not scored.
Preserve highlight differences
The starting edit clips the bright end of the upper gradient. Select two neighbouring white cells: their inputs differ but outputs match. Reduce contrast or offset until differences return. The original is retained: we re-edit it rather than restore an already clipped result.
Exact values are in the point inspector
Grayscale 0…1: black to white.
- Power
- Contrast and offset
- Clamp to [0, 1]
Exact values are in the point inspector
Grayscale 0…1: black to white.
Inspect the selected point
What the plot shows
The curve tells what every input level becomes. The diagonal means no edit; flat sections at 0 and 1 show differences lost to clipping.
- Curve
- No edit
- This pixel: 0.6452; 0.9113
Contrast expands differences; clipping destroys them. Brightening cannot recover clipped information.
Parameters and details
Power tone adjustment, contrast around 0.5 and offset run in that order, then clip to [0,1]. This is a deliberate numerical adjustment, not sRGB encoding. Clipping can map different inputs to the same output, losing invertibility.
Select an image point. Arrows move it; Home and End reach row edges. Viewing does not change the calculation.
Changing the example requires JavaScript and Canvas. Computed images remain available above.
Games
Test your explanation
Question 1 of 5
Pixels were rearranged without changing values. Does the global histogram change?
Exact values are in the point inspector
Grayscale 0…1: black to white.
Exact values are in the point inspector
Grayscale 0…1: black to white.
Exact values are in the point inspector
Grayscale 0…1: black to white.
Exact values are in the point inspector
Grayscale 0…1: black to white.
Choose one answer. It is checked immediately.
Limitations and references
Limits of this example
Scalar curves, 16 histogram bins and a limited 7 × 7 local window. This is not tiled CLAHE, an arbitrary curve editor or ICC colour correction.