source: misclib/fmri_blob_overlay.m @ 80

Last change on this file since 80 was 80, checked in by tjniskan, 10 years ago
  • Changed the historical "an2_" prefix to "aedes_" in all files. NOTE:

Any script or function relying to Aedes functions will be broken
because of this. Just do a search/replace from "an2_" to "aedes_" in
your files and all should be well...

  • Changed the name of an2_readtab.m to a more informative

aedes_readphasetable.m

File size: 6.6 KB
Line 
1function [im_rgb,im,cmap,minmaxT]=fmri_blob_overlay(ImBlob,ImAnat,thold,varargin)
2% FMRI_BLOB_OVERLAY - Display fmri blobs over an anatomical image.
3%
4% Synopsis:
5%       [ImRGB,ImIDX,CMap,minmaxT]=fmri_blob_overlay(ImBlob,ImAnat,THold,
6%                                          param1,value1,param2,value2,...)
7%
8% Description:
9%       The function takes the fMRI activation blob image IMBLOB and the
10%       corresponding anatomical image IMANAT and the T-map threshold THOLD
11%       and returns the thresholded activation blobs overlayed on the
12%       anatomical image as an RGB image (ImRGB), indexed image (ImIDX)
13%       together with the corresponding stacked colormap (CMap), and the
14%       min and max values of the T-map clim. IMBLOB will be reshaped to
15%       match the size of IMANAT if needed.
16%
17%       ImBlob and ImAnat can be paths to the corresponding data files
18%       (NIfTI or VNMR), matrices or Aedes DATA structures. Additional
19%       options are given as parameter/value pairs:
20%
21%       Parameter:              Description:
22%       **********              ************
23%
24%       'BlobCMin'              Min color limit for scaling activation
25%                               blobs. (default = min(ImBlob))
26%
27%       'BlobCMax'              Max color limit for scaling activation
28%                               blobs. (default = max(ImBlob))
29%
30%       'AnatCLim'              A two element vector [CLOW CHIGH] for
31%                               scaling anatomical image. (default =
32%                               min/max)
33%
34%       'BlobCmap'              String of a valid colormap name
35%                               ('jet','hot',etc.) to be used with
36%                               activation blobs. (default = 'hot')
37
38%       'AnatCmap'               String of a valid colormap name
39%                               ('jet','hot',etc.) to be used with
40%                               the anatomical image. (default = 'gray')
41%
42%       'VNMRfix'               'on'/'off'. If set to 'on' the activation
43%                               blobs will be rotate 90 degrees and flipped
44%                               in left/right orientation. (default = 'off')
45%
46%
47% Examples:
48%       [imRGB,imIDX,cmap,minmaxT]=fmri_blob_overlay(...
49%           '/path/to/blobs.nii','/path/to/anatomical.nii',3.1);
50%       imagesc(imRGB,minmaxT),axis image,colorbar,colormap('hot')       
51%
52% See also:
53%       FMRI_CORR, FMRI_SMOOTH, FMRI_FILTER
54
55% This function is a part of Aedes - A graphical tool for analyzing
56% medical images
57%
58% Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi>
59%
60% Department of Physics, Department of Neurobiology
61% University of Kuopio, FINLAND
62%
63% This program may be used under the terms of the GNU General Public
64% License version 2.0 as published by the Free Software Foundation
65% and appearing in the file LICENSE.TXT included in the packaging of
66% this program.
67%
68% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
69% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
70
71% Defaults
72blobcmin = [];
73blobcmax = [];
74anatcmin = [];
75anatcmax = [];
76blobcmap = 'hot';
77anatcmap = 'gray';
78vnmrfix = false;
79voxelsizemin = 0;
80
81% Check number of input arguments
82if nargin<3
83  error('Too few input arguments!')
84end
85
86% Check that the length of varargin is even
87if rem(length(varargin),2)~=0
88  error('Param/value pair number mismatch!');
89end
90
91% Parse varargin ------------------------------
92for ii=1:2:length(varargin)-1
93  param = lower(varargin{ii});
94  value = varargin{ii+1};
95 
96  switch param
97    case 'blobclim'
98      blobcmin = value(1);
99      blobcmax = value(2);
100    case 'blobcmin'
101      blobcmin = value;
102    case 'blobcmax'
103      blobcmax = value;
104    case 'anatclim'
105      anatcmin = value(1);
106      anatcmax = value(2);
107    case 'blobcmap'
108      blobcmap = value;
109    case 'anatcmap'
110      anatcmap = value;
111    case 'voxelsizemin'
112      voxelsizemin = value;
113    case 'vnmrfix'
114      if islogical(value)
115        vnmrfix = value;
116      else
117        if strcmpi(value,'on')
118          vnmrfix = true;
119        end
120      end
121    otherwise
122      error('Unknown parameter %s!',param)
123  end
124end
125
126% Check ImBlob and ImAnat -------------------------
127if isstruct(ImBlob) && isfield(ImBlob,'FTDATA')
128  ImBlob = ImBlob.FTDATA;
129elseif ischar(ImBlob)
130  data = aedes_data_read(ImBlob);
131  ImBlob = double(data.FTDATA);
132  clear data;
133elseif ~isnumeric(ImBlob)
134  error('First input argument not valid!')
135end
136if isstruct(ImAnat) && isfield(ImAnat,'FTDATA')
137  ImAnat = ImAnat.FTDATA;
138elseif ischar(ImAnat)
139  data = aedes_data_read(ImAnat);
140  ImAnat = data.FTDATA;
141  clear data;
142elseif ~isnumeric(ImAnat)
143  error('Second input argument not valid!')
144end
145
146
147% Crop the anatomical image because the FOV in anatomical and blob image is
148% not the same in VNMR EPI-data...
149if vnmrfix
150  %ImAnat = ImAnat(65:65+127,65:65+127,:,:);
151  ImBlob = fliplr(rot90(ImBlob));
152end
153
154
155
156% Check image sizes ------------------------------------
157ImBlobSz = zeros(1,4);
158ImAnatSz = zeros(1,4);
159[ImBlobSz(1),ImBlobSz(2),ImBlobSz(3),ImBlobSz(4)] = size(ImBlob);
160[ImAnatSz(1),ImAnatSz(2),ImAnatSz(3),ImAnatSz(4)] = size(ImAnat);
161if ~isequal(ImBlobSz,ImAnatSz)
162 
163  % Reshape 2D blobs to anatomical size
164  if isequal(ImBlobSz(3:4),[1 1]) && isequal(ImAnatSz(3:4),[1 1])
165    ImBlob=imresize(ImBlob,ImAnatSz(1:2));
166    warning('Resizing blob image...')
167  else
168    error('Blob and anatomical images have to be of same size or 2D!')
169  end
170end
171
172% Threshold blobs
173ind_lo = find(ImBlob<=thold);
174ind_hi = find(ImBlob>thold);
175minT = min(ImBlob(:));
176maxT = max(ImBlob(:));
177%ImBlob(ImBlob<=thold) = 0;
178%ind = find(ImBlob~=0);
179
180% Voxel size threshold
181if voxelsizemin>0
182  ImBloIndHi = ImBlob>thold;
183  ImBloIndHi = bwareaopen(ImBloIndHi,voxelsizemin,8);
184  ind_hi = find(ImBloIndHi);
185end
186
187% Handle clims for blobs and anatomical image -----------
188if ~isempty(blobcmin)
189  ImBlob(ImBlob<blobcmin) = blobcmin;
190  minT = blobcmin;
191end
192if ~isempty(blobcmax)
193  ImBlob(ImBlob>blobcmax) = blobcmax;
194  maxT = blobcmax;
195end
196ImBlob=(ImBlob-min(ImBlob(:)));
197
198if ~isempty(anatcmin)
199  ImAnat(ImAnat<anatcmin) = anatcmin;
200end
201if ~isempty(anatcmax)
202  ImAnat(ImAnat>anatcmax) = anatcmax;
203end
204
205% Construct indexed image -------------------------------
206ImBlob = round(ImBlob./(maxT-minT)*255)+1;
207ImAnat = round(ImAnat./max(ImAnat(:))*255)+1;
208ImRes = ImAnat;
209ImRes(ind_hi) = ImBlob(ind_hi)+256;
210%ImRes = ImRes+ImBlob;
211
212% Construct joint colormap
213ImBlobColormap=eval([blobcmap,'(256)']);
214ImAnatColormap=eval([anatcmap,'(256)']);
215StackedColormap = [ImAnatColormap;ImBlobColormap];
216
217if nargout>0
218  im = ImRes;
219  cmap = StackedColormap;
220  im_rgb = ind2rgb(im,cmap);
221  minmaxT = [minT maxT];
222end
223
224
Note: See TracBrowser for help on using the repository browser.

Powered by Trac 1.0.9.Copyright © Juha-Pekka Niskanen 2008