function MRI_overlay_histogram(mrifilename,figfilename)
%MRI_overlay_histogram(mrifilename,figfilename)
%
% mrifilename = the name of the mri volume overlay
% figfilename = the filename of the png file to output
%
% This function, given an MRI overlay file in any of the accepted
% formats (.nii, .mgz, etc) will output a histogram image
% showing the distribution of data values.
% Also, min,max,median and mean will be output.
%
% Note: you must source the freesurfer environment for this
% to work, because MRIread is called.

d=dir(mrifilename);
if isempty(d)
    disp('ERROR: mri file not found.');
    return;
end
mri = MRIread(mrifilename,0);
v1 = mri.vol(:);
v = v1(find(isfinite(v1)));
fprintf('Total voxels: %d\n',length(v1));
if length(v1) > length(v)
fprintf('There were %d infinite values and %d Nan values excluded.\n',...
    length(find(isinf(v1))),length(find(isnan(v1))));
else
    fprintf('All values were finite (a good thing).\n');
end
close all;
hist(v,100);
exportfig(gcf, figfilename, 'format', 'png', 'color', 'cmyk', ...
     'height', 6, 'FontMode', 'fixed', 'FontSize', 12)
fprintf('Min value: %f\n',min(v));
fprintf('Max value: %f\n',max(v));
fprintf('Median value: %f\n',median(v));
fprintf('Mean value: %f\n',mean(v));

UserContributions/Scripts/goldenholz/MRI_overlay_histogram.m (last edited 2009-03-10 14:16:46 by DanielGoldenholz)