Adjust histogram of 2-D image to match histogram of reference image
transforms the 2-D grayscale or truecolor image J
= imhistmatch(I
,ref
)I
returning
output image J
whose histogram approximately matches the
histogram of the reference image ref
.
If both I
and ref
are
truecolor images, then imhistmatch
matches each color
channel of I
independently to the corresponding
color channel of ref
.
If I
is a truecolor RGB image and ref
is a grayscale
image, then imhistmatch
matches each channel of
I
against the single histogram derived from
ref
.
If I
is a grayscale image, then ref
must also be a
grayscale image.
Images I
and ref
can be any of the permissible data
types and need not be equal in size.
uses J
= imhistmatch(I
,ref
,nbins
)nbins
equally spaced bins within the appropriate range
for the given image data type. The returned image J
has no
more than nbins
discrete levels.
If the data type of the image is either single
or double
, then the histogram range is [0,
1].
If the data type of the image is uint8
, then
the histogram range is [0, 255].
If the data type of the image is uint16
, then
the histogram range is [0, 65535].
If the data type of the image is int16
, then
the histogram range is [-32768, 32767].
uses name-value pairs to change the behavior of the histogram matching
algorithm.J
= imhistmatch(___,Name,Value
)
[
returns the histogram of the reference image J
,hgram
]
= imhistmatch(___)ref
used for
matching in hgram
. hgram
is a
1-by-nbins
(when ref
is grayscale)
or a 3-by-nbins
(when ref
is
truecolor) matrix, where nbins
is the number of histogram
bins. Each row in hgram
stores the histogram of a single
color channel of ref
.
The objective of imhistmatch
is to transform image I
such that the histogram of image J
matches the histogram derived
from image ref
. It consists of nbins
equally
spaced bins which span the full range of the image data type. A consequence of matching
histograms in this way is that nbins
also represents the upper
limit of the number of discrete data levels present in image
J
.
An important behavioral aspect of this algorithm to note is that as nbins
increases in value, the degree of rapid fluctuations between adjacent populated peaks in
the histogram of image J
tends to increase. This can be seen in the
following histogram plots taken from the 16–bit grayscale MRI example.
An optimal value for nbins
represents a
trade-off between more output levels (larger values of nbins
)
while minimizing peak fluctuations in the histogram (smaller values
of nbins
).