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 imresize.
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 ref.
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')