Home > bioelectromagnetism > avw_histogram.m

avw_histogram

PURPOSE ^

avw_histogram

SYNOPSIS ^

function [bins,freq,freq_nozero] = avw_histogram(avw,binInterval,binNumber,plot)

DESCRIPTION ^

 avw_histogram

 [bins,freq,freq_nozero] = avw_histogram(avw,binInterval,binNumber,plot)

 avw  - an Analyze 7.5 data struct, see avw_read

 binInterval - the intensity interval between bins (default = 5)

 binNumber - the total number of bins (default = 255)

 If binInterval is specified, it takes precedence over binNumber

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [bins,freq,freq_nozero] = avw_histogram(avw,binInterval,binNumber,plot)
0002 
0003 % avw_histogram
0004 %
0005 % [bins,freq,freq_nozero] = avw_histogram(avw,binInterval,binNumber,plot)
0006 %
0007 % avw  - an Analyze 7.5 data struct, see avw_read
0008 %
0009 % binInterval - the intensity interval between bins (default = 5)
0010 %
0011 % binNumber - the total number of bins (default = 255)
0012 %
0013 % If binInterval is specified, it takes precedence over binNumber
0014 %
0015 
0016 % $Revision: 1.2 $ $Date: 2005/03/18 21:48:25 $
0017 
0018 % Licence:  GNU GPL, no implied or express warranties
0019 % History:  08/2004, Darren.Weber_at_radiology.ucsf.edu
0020 %
0021 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0022 
0023 version = '[$Revision: 1.2 $]';
0024 fprintf('\nAVW_HISTOGRAM [v%s]\n',version(12:16));  tic;
0025 
0026 if ~exist('binInterval','var'), binInterval = 5; end
0027 if isempty(binInterval), binInterval = 5; end
0028 
0029 if ~exist('binNumber','var'), binNumber = 255; end
0030 if isempty(binNumber), binNumber = 255; end
0031 
0032 if ~exist('plot','var'), plot = 1; end
0033 if isempty(plot), plot = 1; end
0034 
0035 % would be nice to use bins that reflect
0036 % the bits per pixel, but it seems to take
0037 % forever for a 16 bit image, otherwise
0038 % use this code:
0039 %     %check the bits per pixel of avw
0040 %     bitpix = avw.hdr.dime.bitpix;
0041 %     % set the bins according to the data type
0042 %     if bitpix <= 8, bins = 0:255; end
0043 %     if bitpix > 8,  bins = 0:65535; end
0044 
0045 %bins = linspace(0,intensity_max,255);
0046 
0047 intensity_min = min(min(min(avw.img)));
0048 intensity_max = max(max(max(avw.img)));
0049 
0050 % the determination of bins should incorporate binInterval and binNumber,
0051 % for now, it only uses binInterval
0052 bins = [intensity_min:binInterval:intensity_max]';
0053 
0054 binNumber = length(bins);
0055 
0056 fprintf('...calculating histogram for %d bins.\n',binNumber);
0057 
0058 freq = zeros(1,binNumber);
0059 
0060 for i=1:size(avw.img,3),
0061     % hist returns the counts for each bin for every column of the slice
0062     % input avw.img here.  Below, we sum across columns to get the
0063     % frequency count for the whole slice
0064     n = hist(avw.img(:,:,i), bins);
0065     if i == 1,
0066         freq = sum(n,2);
0067     else
0068         freq_slice = sum(n,2);
0069         freq = freq + freq_slice;
0070     end
0071 end
0072 
0073 if plot,
0074     figure('name','intensity histogram');
0075     bar(bins,freq);
0076 end
0077 
0078 freq_nozero = [freq(1) * 0; freq(2:end)];
0079 
0080 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003