Percentile normalization¶
| Fact | Value |
|---|---|
| Also called | Auto contrast, Percentile stretch, Min-max normalization |
| Status | Implemented and tested |
| Family | Enhancement, illumination and color |
| Engine | Browser |
| Type | Nonlinear, point, percentile linear stretch |
| Output | Image |
| Operator shown as | point-transfer (exact) |
| Support radius | 0 |
| Code | web/src/core/filters/enhancement/histogram.ts, percentileNormalizeFilter |
| Operator code | web/src/core/filters/enhancement/histogram.ts, percentileTable |
| Channels | Brightness only, RGB |
Overview¶
Percentile normalization stretches the image so that its darkest few percent become black and its brightest few percent become white. It finds the stretch from the image itself. Unlike min-max normalization, a few extreme pixels cannot stop it.
How it works¶
- Count how many pixels have each level.
- Find the levels at the low and the high percentile.
- Map the low one to 0 and the high one to 255 with a straight line.
- Clip everything outside to 0 or 255.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(I\): Input value from 0 to 255
- \(P_q\): The q-th percentile of the image values
- \(p_{\text{lo}}, p_{\text{hi}}\): The values that map to 0 and 255
P_q is the q-th percentile of the image values, rounded to the levels 0 to 255. It uses the linear rule of numpy.percentile: the sorted values are indexed from 0 to N - 1, and position (N - 1) q / 100 is interpolated between its two neighbors. The low percentile maps to 0, the high one to 255, and the line between them is clipped at both ends. Percentiles 0 and 100 give min-max normalization. When p_hi is not above p_lo, as in a flat image, the image stays as it is. Values between two levels take the output interpolated between them.
A percentile is a value below which a given share of the pixels lies. The filter uses the linear rule of numpy.percentile. It sorts the values, finds the position (N - 1) q / 100, and interpolates between the two values next to it. The histogram gives the sorted values without sorting, since all values are levels from 0 to 255.
Kernel or operator¶
The curve depends on the image, so the Inspector shows its formula. The Point-op curve in the Learn panel draws the curve for the open image, with the histograms before and after.
Algorithm¶
- Count the histogram of the levels of the whole image.
- Find the low and high percentiles from the cumulative counts.
- Build the 256-entry clipped line and apply it to every pixel.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Low percentile low |
1 | 0 to 50 % | The percentile that becomes black. |
High percentile high |
99 | 50 to 100 % | The percentile that becomes white. |
Channels channelScope |
Brightness only | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
percentileNormalizeFilter in web/src/core/filters/enhancement/histogram.ts finds the percentiles with histogramPercentile and builds the curve with percentileTable. histogram256 counts the levels of the whole plane, and applyTable applies the curve, interpolating between levels. The filter is global, so it always sees the whole image.
Worked example¶
| Percentiles | 0 and 100 | 0.5 and 99.5 | 1 and 99 | 5 and 95 |
|---|---|---|---|---|
| p_lo | 0 | 97 | 97 | 97 |
| p_hi | 255 | 142 | 141 | 131 |
The percentiles of the speckled image of the figure. The specks are pure black and white, so min-max normalization finds 0 and 255 and changes nothing. From 0.5 and 99.5 on, the specks fall outside the percentiles, and the stretch works on the real range of the image.
Complexity¶
- Time: \(O(N)\)
- Memory: \(O(1)\)
N is the number of pixels. One pass counts the histogram, a second applies the 256-entry curve.
Artifacts and limitations¶
Limitations
- Clips the chosen fraction of pixels at each end.
- One curve for the whole image. Local methods such as CLAHE adapt per region.
Artifacts
- Clipped highlights or shadows when the percentiles are far from 0 and 100.
- Color shifts with RGB scope, since each channel stretches on its own.
Tests¶
The reference uses numpy.percentile on the test plane and the same clipped line. The cases include percentiles 0 and 100, and equal percentiles, where the image stays as it is.
References¶
- NumPy documentation, numpy.percentile. https://numpy.org/doc/stable/reference/generated/numpy.percentile.html
- scikit-image documentation, skimage.exposure.rescale_intensity. https://scikit-image.org/docs/stable/api/skimage.exposure.html#skimage.exposure.rescale_intensity