


% L1-HISTOGRAM (c) Luca Baldassarre CS Dept, UCL, London, UK 8th May 2012 l.baldassarre@cs.ucl.ac.uk baldazen@gmail.com Atlas-based region histograms. For each column of beta, l1_histogram(beta, atlas) computes the relative amount of the l1_norm that is contained in each region defined by the atlas. Atlas is a nx1 vector, where n = size(beta,1), such that atlas(i) is the region to which voxel i belongs. H = l1_histogram(beta, atlas) only computes the standard histogram [H HN] = l1_histogram(beta, atlas) also computes the normalized histogram, where each bin is normalized by the region's volume (i.e. the number of voxels it contains). [H HN sorted_regions] = l1_histogram(beta, atlas) return the list of regions, sorted in descending order according to the normalized histogram.


0001 function [H HN SN idfeatroi] = prt_region_histogram(beta, atlas) 0002 0003 %% L1-HISTOGRAM 0004 % (c) Luca Baldassarre 0005 % CS Dept, UCL, London, UK 0006 % 8th May 2012 0007 % l.baldassarre@cs.ucl.ac.uk 0008 % baldazen@gmail.com 0009 % 0010 % Atlas-based region histograms. 0011 % 0012 % For each column of beta, l1_histogram(beta, atlas) computes the relative amount of 0013 % the l1_norm that is contained in each region defined by the atlas. 0014 % Atlas is a nx1 vector, where n = size(beta,1), such that atlas(i) is the 0015 % region to which voxel i belongs. 0016 % 0017 % H = l1_histogram(beta, atlas) only computes the standard histogram 0018 % 0019 % [H HN] = l1_histogram(beta, atlas) also computes the normalized 0020 % histogram, where each bin is normalized by the region's volume (i.e. the 0021 % number of voxels it contains). 0022 % 0023 % [H HN sorted_regions] = l1_histogram(beta, atlas) return the list of 0024 % regions, sorted in descending order according to the normalized 0025 % histogram. 0026 0027 0028 % Number of vectors 0029 m = size(beta, 2); 0030 % Number of regions 0031 R = max(atlas); 0032 % Initial region index 0033 r_min = min(atlas); 0034 % Add an offset to account for matlab indexing (it starts from 1) 0035 if r_min == 0 0036 correction = 1; 0037 else 0038 correction = 0; 0039 end 0040 0041 H = zeros(R,m); 0042 S = zeros(R,m); 0043 for km = 1:m 0044 disp(['Fold ',num2str(km)]) 0045 % Compute relative frequencies for each region 0046 for r = r_min:R 0047 tmp = sum(abs(beta(atlas == r,km))); 0048 H(r+correction,km) = tmp; 0049 0050 %compute the proportions of positive versus negative weights 0051 S(r+correction,km) = length(find(beta(atlas == r,km)>0)); 0052 end 0053 end 0054 0055 %% COMPUTE NORMALIZED HISTOGRAMS AND FULL INTERSECTION 0056 if nargout > 1 0057 % Compute volumes according to atlas 0058 volume = zeros(R,1); 0059 idfeatroi = cell(R,1); 0060 for r = r_min:R 0061 volume(r+correction) = sum(atlas == r); 0062 idfeatroi{r+correction} = find(atlas==r); 0063 end 0064 HN = H./repmat(volume,1,m); 0065 SN = S./repmat(volume,1,m); 0066 end