Adjust histogram of N-D image to match histogram of reference image
B = imhistmatchn(A,ref)
B = imhistmatchn(A,ref,nbins)
[B,hgram] = imhistmatchn(___)
If the data type of the image is:
the histogram range is [0, 1].
uint8, the histogram range is [0,
uint16, the histogram range is
int16, the histogram range is [-32768,
Load an N-D grayscale image into the workspace. Also load a grayscale image to provide a reference histogram.
load mri D load mristack
Display the original volume as slices.
figure montage(D,'DisplayRange',) title('Original 3-D Image')
Reshape the reference as a stack of grayscale slices for display.
ref = reshape(mristack,[256,256,1,21]);
Display the reference volume as slices. To display correctly on the screen, the reference volume is downsized by a factor of 0.5 using
ref_downsized = imresize(ref,0.5); figure montage(ref_downsized,'DisplayRange',) title('Reference 3-D Image')
Match the histogram of
D to the histogram of the fullsize
Dmatched = imhistmatchn(D,ref);
Display the output. Observe that the brightness levels of the output more closely match the reference image than the original image.
figure montage(Dmatched,'DisplayRange',) title('Histogram Matched MRI')
A— Input image
Input image to be transformed, specified as an N-D grayscale image.
ref— Reference image whose histogram is the reference histogram
nbins— Number of equally spaced bins in reference histogram
Number of equally spaced bins in reference histogram, specified
as a positive integer.
nbins also represents
the upper limit of the number of discrete data levels present in output
B— Output image
Output image, returned as an N-D grayscale image. The output
image is derived from image
A whose histogram
is an approximate match to the histogram of input image
nbins equally spaced bins. Image
of the same size and data type as input image
nbins represents the upper limit
of the number of discrete levels contained in image