Adjust histogram of N-D image to match histogram of reference image
If the data type of the image is:
double, the histogram range is [0, 1].
uint8, the histogram range is [0, 255].
uint16, the histogram range is [0, 65535].
int16, the histogram range is [-32768, 32767].
Match Histograms of Multidimensional Images
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
N-D grayscale 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
64 (default) | positive integer
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
N-D grayscale 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
ref built with
nbins equally spaced bins. Image
B is of the same size and data type as input image
A. Input argument
represents the upper limit of the number of discrete levels contained in