histEqualize

Histogram Equalization.

Equalize histogram of given image slice. Slice can be 2D for grayscale, and 3D for color images. If 3D slice is given, histogram is applied separatelly for each channel.

histEqualize
(
T
HistogramType
SliceKind kind
size_t[] packs
)
(
Slice!(kind, packs, T*) slice
,
HistogramType histogram
,
Slice!(Contiguous, packs, T*) prealloc = emptySlice!(packs, T)
)
in { static assert (packs.length == 1, "Packed slices are not allowed."); assert (!slice.empty()); static if (isDynamicArray!HistogramType) { assert (histogram.length == T.max + 1, "Invalid histogram length."); } }

Parameters

HistogramType

(template parameter) Histogram type, see calcHistogram function for details.

slice
Type: Slice!(kind, packs, T*)

Input image slice.

histogram
Type: HistogramType

Histogram values for input image slice.

prealloc
Type: Slice!(Contiguous, packs, T*)

Optional pre-allocated buffer where equalized image is saved.

Return Value

Type: auto

Copy of input image slice with its histogram values equalized.

Examples

1 import dcv.core, dcv.io, dcv.imgproc, dcv.plot;
2 
3 void main()
4 {
5     Image image = imread("dcv/examples/data/lena.png");
6 
7     auto slice = image.sliced.rgb2gray;
8     auto equalized = slice.histEqualize(slice.flattened.calcHistogram);
9 
10     slice.imshow("Original");
11     equalized.imshow("Equalized");
12 
13     waitKey();
14 }

Example code will equalize grayscale Lena image, from this:

$(IMAGE https://github.com/libmir/dcv/blob/master/examples/data/lena_gray.png?raw=true)

... to this:

$(IMAGE https://github.com/libmir/dcv/blob/master/examples/data/histEqualExample.png?raw=true)

Note: For more valid color histogram equalization results, try converting image to HSV color model to perform equalization for V channel, to alter the color as less as possible.

Meta