Point operations modify the intensity of a pixel using only that pixel’s own value, in isolation from its neighbours. May use statistical data relating to other pixels, such as the image histogram.
Homogeneous iff the operation is independent of pixel location.
Lookup Table
A lookup table (LUT) maps the current pixel value to an index, returning a new value from the table.
- Enables on the fly processing, especially on hardware platforms
- Changing table content changes the operation without changing any code
Examples:
- Pseudo colouring, e.g. mapping thermal image temperature to RGB
- Compensating for non-linearity in sensor elements
Grey Level Histogram
The grey level histogram shows the frequency of occurrence of each intensity level in an image, regardless of pixel position. Its shape describes overall brightness and contrast.
Normalized histogram:
- number of pixels with intensity
- total number of pixels
Defines the probability of intensity level in the image.
Accumulated histogram:
Defines the accumulated probability of pixels with intensity level .
Characteristics
- Position independent
The histogram ignores where pixels are. Rearranging the pixels leaves it unchanged, so different images can share one histogram. - Size independent
The normalized histogram holds proportions, so images of different sizes can be compared. - Sums to 1
. The accumulated histogram never decreases and reaches 1 at the highest level. - Gives mean and spread
Brightness is the mean and contrast is the standard deviation of the distribution.
- mean intensity
- variance of intensity
| Shape | Meaning |
|---|---|
| Concentrated at low levels | Dark image. |
| Concentrated at high levels | Bright image. |
| Narrow | Low contrast. |
| Wide | High contrast. |
| 2 separated peaks | Objects and background with different intensities. A threshold between the peaks separates them. |
Effect of a point operation on the histogram:
- A one-to-one mapping moves bins without changing their heights.
- A many-to-one mapping merges bins and adds their heights. The merged levels cannot be told apart afterwards.
- No point operation splits a bin, since all pixels with the same input level get the same output level. So a histogram can only be approximated, and unused levels appear as gaps.
Brightness and Contrast
Brightness and contrast are the position and the width of the same histogram. Both are described as point operations mapping input intensity to output intensity .
- Brightness
Mean intensity. A shift slides the histogram along the intensity axis, keeping its shape and width. - Contrast
Spread of intensities. Histogram width, the gap between the darkest and brightest points, measures it. A gain stretches the histogram wider.
Here:
- input intensity
- output intensity
- shift constant, added to move brightness
- gain constant, multiplied to change contrast
Shifting the histogram changes brightness only. Every pair of pixels keeps the same intensity gap, so contrast is unaffected.
Point Processing Functions
Common transformations applied to each pixel, typically implemented as a LUT mapping input intensity to output intensity .
| Function | Equation |
|---|---|
| Identity Output equals input. | |
| Digital negative Inverts intensity. | |
| Square root Compresses bright values and expands dark ones. maps the top level to itself. | |
| Contrast stretching Piecewise linear expansion of a chosen intensity range. | |
| Normalizing Rescales intensities to use the full available range. | |
| Clipping Forces values outside a chosen range to the range boundary. | |
| Intensity level slicing Highlights a chosen intensity band, suppressing all others. | |
| Bit slicing Extracts bit-plane of the pixel value. The result is or . | |
| Range stretching or compression Maps a chosen input range onto a different output range. It stretches when the output range is wider than the input range, and compresses when it is narrower. | |
| Histogram equalization Redistributes intensities to make the histogram more uniform. |
Here:
- number of grey levels
- lower and upper bounds of the chosen range
- scaling constant
-
control points of the piecewise linear curve
- limits of the input range
- limits of the output range
- bit-plane index, with the least significant bit
- accumulated histogram
Normalizing is range stretching with the output range and the input range set to the image minimum and maximum.
Histogram Matching
Also known as histogram specification. The process of adjusting a test image so its grey level distribution follows a given reference distribution.
The reference is supplied as a 256-element array holding the reference CDF, one value per grey level.
Procedure:
- Compute the test image histogram, then its CDF
- For each test level , find the reference level whose CDF value is closest to
- Store in a 256-entry LUT
- Apply the LUT to every pixel
- accumulated probability of test level
- accumulated probability of reference level
Histogram equalization is the special case where the reference CDF is linear. Matching 2 levels through equal CDF values preserves their relative ordering.
For a colour image, each channel is matched independently against the reference channel.
def cdf(pixels):
# count how many pixels have each intensity
hist = [0] * 256
for v in pixels:
hist[v] += 1
# accumulate the counts and divide by the total to get the CDF
total = len(pixels)
running, out = 0, [0.0] * 256
for i, c in enumerate(hist):
running += c
out[i] = running / total
return out
def match(test_pixels, ref_cdf):
ct = cdf(test_pixels)
# build the LUT: for each test level g, pick the reference
# level r whose CDF value is closest to the test CDF value
lut = [0] * 256
for g in range(256):
best_r = 0
best_diff = abs(ref_cdf[0] - ct[g])
for r in range(1, 256):
diff = abs(ref_cdf[r] - ct[g])
if diff < best_diff:
best_diff = diff
best_r = r
lut[g] = best_r
# remap every pixel through the LUT
out = []
for v in test_pixels:
out.append(lut[v])
return out
For a colour image, match each channel against that channel’s reference CDF.
Multiple Images and Histograms
Each image has its own , so every image needs its own LUT. The reference CDF is the only input shared between images.
- 1 reference for all images
Compute the reference CDF once, then build and apply one LUT per image. All outputs follow the same distribution, so brightness and contrast are consistent across the set. - 1 reference per image
Pair each image with its reference CDF, then match each pair separately. - References not paired with images
Give each image the reference whose CDF is closest, then match.
The distance between an image and a reference is the total absolute difference of their CDFs.
Image takes the reference . When each reference may be used by only 1 image, solve an assignment problem on the matrix , for example with the Hungarian algorithm.
def match_to_closest(images, ref_cdfs):
out = []
for pixels in images:
ct = cdf(pixels)
# pick the reference whose CDF differs least from the image CDF
best = min(ref_cdfs, key=lambda rc: sum(abs(a - b) for a, b in zip(ct, rc)))
out.append(match(pixels, best))
return out
Worked Example
Match a 4-pixel test image to a reference CDF over 4 grey levels .
Test pixels: .
Test histogram: , total .
Test CDF : .
Reference CDF : .
Solution Reveal Hide
Mapping:
- , : closest is , so
- , : closest is , so
- , :
- , : , so
Output pixels: .