ContrastStretch - Serabe/rinzelight GitHub Wiki
Contrast stretching maps the pixels that were in a region to fit the whole spectre.
It maps them linearly if the pixel was in the region before, it maps them to 0 (quantum-range) it they were below (above). Since stretching an image whose pixels lie all in the region does nothing, the parameters mean how many pixels should be “ignored”.
In first place, constrast-stretch
computes the black and white points. These points are just thresholds for getting the new region. Then it asks for the histogram an calculates the limit of the region. Finally, it applies a lookup table to map all the pixels in the region and ignore the rest.
If the arguments are numbers, they are considered as the number of pixel that should be below or above the new region.
The only Strings that the method accept are of the form “N.N%”. They are used for calculating how many pixels should be below or above the region.
Considered the function call (contrast-stretch img 1000 3000)
. What do 1000 and 3000 mean?
- 1000: there must be at least 1000 pixels whose value lied below the region and that will be mapped to 0.
- 3000: there must be at most
number_of_pixels - 3000
whose value lied above the region and that will be mapped to(quantum-range)
.
(cs-example "0.02-0.99" (* 0.02 size) (* 0.99 size))
(normalize
)
(cs-example "2%" "99%")
(normalize
)
(cs-example "20%" "90%")
(cs-example "0.2-0.9" (* 0.2 size) (* 0.9 size))