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)
)

Parameters

HistogramType

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

slice Slice!(kind, packs, T*)

Input image slice.

histogram HistogramType

Histogram values for input image slice.

prealloc 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

import dcv.core, dcv.io, dcv.imgproc, dcv.plot;

void main()
{
    Image image = imread("dcv/examples/data/lena.png");

    auto slice = image.sliced.rgb2gray;
    auto equalized = slice.histEqualize(slice.flattened.calcHistogram);

    slice.imshow("Original");
    equalized.imshow("Equalized");

    waitKey();
}

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