Enhance contrast using histogram equalization
transforms the colormap associated with the indexed image
newmap = histeq(
so that the histogram of the gray component of the indexed image
newmap) approximately matches
the target histogram
function returns the transformed colormap in
length(hgram) must be the same as
Read an image into the workspace.
I = imread('tire.tif');
Enhance the contrast of an intensity image using histogram equalization.
J = histeq(I);
Display the original image and the adjusted image.
imshowpair(I,J,'montage') axis off
Display a histogram of the original image.
Display a histogram of the processed image.
Load a 3-D dataset.
Perform histogram equalization.
enhanced = histeq(mristack);
Display the first slice of data for the original image and the contrast-enhanced image.
figure subplot(1,2,1) imshow(mristack(:,:,1)) title('Slice of Original Image') subplot(1,2,2) imshow(enhanced(:,:,1)) title('Slice of Enhanced Image')
I— Grayscale image
Grayscale image, specified as a numeric array of any dimension.
hgram— Target histogram
Target histogram, specified as a numeric vector.
hgram has equally spaced
bins with intensity values in the appropriate range:
[0, 1] for images of class
[0, 255] for images of class
[0, 65535] for images of class
[-32768, 32767] for images of class
n— Number of discrete gray levels
64(default) | positive integer
Number of discrete gray levels, specified as a positive integer.
X— Indexed image
Indexed image, specified as a numeric array of any dimension. The values
X are an index into the colormap
J— Transformed grayscale image
Transformed grayscale image, returned as a numeric array of the same size
and class as the input image
newmap— Transformed colormap
Transformed colormap, specified as an n-by-3 numeric matrix with values in the range [0, 1]. Each row is a three-element RGB triplet that specifies the red, green, and blue components of a single color of the colormap.
c0 is the cumulative
histogram of the input image
c1 is the cumulative sum of
hgram for all intensities k. This
minimization is subject to these constraints:
T must be monotonic
c1(T(a)) cannot overshoot c0(a) by more than half the distance between the histogram counts at a
histeq uses the transformation b =
T(a) to map the gray levels in
X (or the colormap) to their new values.
If you do not specify
histeq creates a
hgram = ones(1,n)*prod(size(A))/n;
and then applies the previous algorithm.
Usage notes and limitations:
histeq supports the generation of C
code (requires MATLAB®
Coder™). Note that if you choose the generic
MATLAB Host Computer
histeq generates code that uses a precompiled,
platform-specific shared library. Use of a shared library preserves performance optimizations
but limits the target platforms for which code can be generated. For more information, see Types of Code Generation Support in Image Processing Toolbox.
When generating code,
not support indexed images.
This function fully supports GPU arrays. For more information, see Image Processing on a GPU.