Adjust histogram of 2-D image to match histogram of reference image
transforms the 2-D grayscale or truecolor imageJ
= imhistmatch(I
,ref
)I
returning output imageJ
whose histogram approximately matches the histogram of the reference imageref
.
If bothI
andref
are truecolor images, thenimhistmatch
matches each color channel ofI
independently to the corresponding color channel ofref
.
IfI
is a truecolor RGB image andref
is a grayscale image, thenimhistmatch
matches each channel ofI
against the single histogram derived fromref
.
IfI
is a grayscale image, thenref
must also be a grayscale image.
ImagesI
andref
can be any of the permissible data types and need not be equal in size.
usesJ
= imhistmatch(I
,ref
,nbins
)nbins
equally spaced bins within the appropriate range for the given image data type. The returned imageJ
has no more thannbins
discrete levels.
If the data type of the image is eithersingle
ordouble
then the histogram range is [0, 1].
If the data type of the image isuint8
then the histogram range is [0, 255].
If the data type of the image isuint16
then the histogram range is [0, 65535].
If the data type of the image isint16
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 imageJ
,hgram
] = imhistmatch(___)ref
used for matching inhgram
.hgram
is a 1-by-nbins
(whenref
is grayscale) or a 3-by-nbins
(whenref
is truecolor) matrix, wherenbins
is the number of histogram bins. Each row inhgram
stores the histogram of a single color channel ofref
.
The objective ofimhistmatch
is to transform imageI
such that the histogram of imageJ
matches the histogram derived from imageref
. It consists ofnbins
equally spaced bins which span the full range of the image data type. A consequence of matching histograms in this way is thatnbins
also represents the upper limit of the number of discrete data levels present in imageJ
.
An important behavioral aspect of this algorithm to note is that asnbins
increases in value, the degree of rapid fluctuations between adjacent populated peaks in the histogram of imageJ
tends to increase. This can be seen in the following histogram plots taken from the 16–bit grayscale MRI example.
An optimal value fornbins
代表着更多的产出水平之间的权衡(larger values ofnbins
) while minimizing peak fluctuations in the histogram (smaller values ofnbins
).