source: misclib/fmri_blob_overlay.m @ 82

Last change on this file since 82 was 82, checked in by tjniskan, 10 years ago
  • Some minor modifications to aedes_readfid.m
  • Added BOLD strength estimation to

plugins/fmri_plugins/basic_fmri_analysis.m

  • Changed the image in about dialog
  • Added support for negative threshold in misclib/fmri_blob_overlay.m

M misclib/fmri_blob_overlay.m
M aedes_helpabout.m
M plugins/fmri_plugins/basic_fmri_analysis.m
M aedes_readfid.m
M aedes_revision.m

File size: 8.5 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%       'Deactivation'         'on','off': Select if deactivation blobs are also
25%                               displayed (default = 'off')
26%
27%       'BlobCMin'              Min color limit for scaling activation
28%                               blobs. (default = min(ImBlob))
29%
30%       'BlobCMax'              Max color limit for scaling activation
31%                               blobs. (default = max(ImBlob))
32%
33%       'AnatCLim'              A two element vector [CLOW CHIGH] for
34%                               scaling anatomical image. (default =
35%                               min/max)
36%
37%       'BlobCmap'              String of a valid colormap name
38%                               ('jet','hot',etc.) to be used with
39%                               activation blobs. (default = 'hot')
40%
41%       'BlobNegCmap'           String of a valid colormap name
42%                               ('cool','jet',etc.) to be used with
43%                               deactivation blobs. (default = 'cool')
44
45%       'AnatCmap'               String of a valid colormap name
46%                               ('jet','hot',etc.) to be used with
47%                               the anatomical image. (default = 'gray')
48%
49%       'VNMRfix'               'on'/'off'. If set to 'on' the activation
50%                               blobs will be rotate 90 degrees and flipped
51%                               in left/right orientation. (default = 'off')
52%
53%
54% Examples:
55%       [imRGB,imIDX,cmap,minmaxT]=fmri_blob_overlay(...
56%           '/path/to/blobs.nii','/path/to/anatomical.nii',3.1);
57%       imagesc(imRGB,minmaxT),axis image,colorbar,colormap('hot')       
58%
59% See also:
60%       FMRI_CORR, FMRI_SMOOTH, FMRI_FILTER
61
62% This function is a part of Aedes - A graphical tool for analyzing
63% medical images
64%
65% Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi>
66%
67% Department of Physics, Department of Neurobiology
68% University of Kuopio, FINLAND
69%
70% This program may be used under the terms of the GNU General Public
71% License version 2.0 as published by the Free Software Foundation
72% and appearing in the file LICENSE.TXT included in the packaging of
73% this program.
74%
75% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
76% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
77
78% Defaults
79blobcmin = [];
80blobcmax = [];
81blobnegcmin = [];
82blobnegcmax = [];
83anatcmin = [];
84anatcmax = [];
85deactivations = false;
86blobcmap = 'hot';
87blobnegcmap = 'cool';
88anatcmap = 'gray';
89vnmrfix = false;
90voxelsizemin = 0;
91
92% Check number of input arguments
93if nargin<3
94  error('Too few input arguments!')
95end
96
97% Check that the length of varargin is even
98if rem(length(varargin),2)~=0
99  error('Param/value pair number mismatch!');
100end
101
102% Parse varargin ------------------------------
103for ii=1:2:length(varargin)-1
104  param = lower(varargin{ii});
105  value = varargin{ii+1};
106 
107  switch param
108    case 'deactivation'
109      if strcmpi(value,'on')
110        deactivations = true;
111      end
112    case 'blobclim'
113      blobcmin = value(1);
114      blobcmax = value(2);
115    case 'blobcmin'
116      blobcmin = value;
117    case 'blobnegcmin'
118      blobnegcmin = abs(value);
119    case 'blobnegcmax'
120      blobnegcmax = abs(value);
121    case 'blobcmax'
122      blobcmax = value;
123    case 'anatclim'
124      anatcmin = value(1);
125      anatcmax = value(2);
126    case 'blobcmap'
127      blobcmap = value;
128    case 'blobnegcmap'
129      blobnegcmap = value;
130    case 'anatcmap'
131      anatcmap = value;
132    case 'voxelsizemin'
133      voxelsizemin = value;
134    case 'vnmrfix'
135      if islogical(value)
136        vnmrfix = value;
137      else
138        if strcmpi(value,'on')
139          vnmrfix = true;
140        end
141      end
142    otherwise
143      error('Unknown parameter %s!',param)
144  end
145end
146
147% Check ImBlob and ImAnat -------------------------
148if isstruct(ImBlob) && isfield(ImBlob,'FTDATA')
149  ImBlob = ImBlob.FTDATA;
150elseif ischar(ImBlob)
151  data = aedes_data_read(ImBlob);
152  ImBlob = double(data.FTDATA);
153  clear data;
154elseif ~isnumeric(ImBlob)
155  error('First input argument not valid!')
156end
157if isstruct(ImAnat) && isfield(ImAnat,'FTDATA')
158  ImAnat = ImAnat.FTDATA;
159elseif ischar(ImAnat)
160  data = aedes_data_read(ImAnat);
161  ImAnat = data.FTDATA;
162  clear data;
163elseif ~isnumeric(ImAnat)
164  error('Second input argument not valid!')
165end
166
167
168% Crop the anatomical image because the FOV in anatomical and blob image is
169% not the same in VNMR EPI-data...
170if vnmrfix
171  %ImAnat = ImAnat(65:65+127,65:65+127,:,:);
172  ImBlob = fliplr(rot90(ImBlob));
173end
174
175if length(thold)==2
176  if isnan(thold(2))
177    thold = thold(1);
178  else
179    deactivations = true;
180  end
181end
182
183if deactivations
184  tholdneg = abs(thold(2));
185  thold = thold(1);
186end
187
188% Check image sizes ------------------------------------
189ImBlobSz = zeros(1,4);
190ImAnatSz = zeros(1,4);
191[ImBlobSz(1),ImBlobSz(2),ImBlobSz(3),ImBlobSz(4)] = size(ImBlob);
192[ImAnatSz(1),ImAnatSz(2),ImAnatSz(3),ImAnatSz(4)] = size(ImAnat);
193if ~isequal(ImBlobSz,ImAnatSz)
194 
195  % Reshape 2D blobs to anatomical size
196  if isequal(ImBlobSz(3:4),[1 1]) && isequal(ImAnatSz(3:4),[1 1])
197    ImBlob=imresize(ImBlob,ImAnatSz(1:2));
198    warning('Resizing blob image...')
199  else
200    error('Blob and anatomical images have to be of same size or 2D!')
201  end
202end
203
204ImBlobNeg = -ImBlob;
205
206% Threshold blobs
207ind_lo = find(ImBlob<=thold);
208ind_hi = find(ImBlob>thold);
209minT = min(ImBlob(:));
210maxT = max(ImBlob(:));
211
212if deactivations
213  ind_neg_lo = find(ImBlobNeg<=tholdneg);
214  ind_neg_hi = find(ImBlobNeg>tholdneg);
215  minTneg = min(ImBlobNeg(:));
216  maxTneg = max(ImBlobNeg(:));
217end
218%ImBlob(ImBlob<=thold) = 0;
219%ind = find(ImBlob~=0);
220
221% Voxel size threshold
222if voxelsizemin>0
223  ImBloIndHi = ImBlob>thold;
224  ImBloIndHi = bwareaopen(ImBloIndHi,voxelsizemin,8);
225  ind_hi = find(ImBloIndHi);
226end
227if deactivations
228  ImBloNegIndHi = ImBlobNeg>tholdneg;
229  ImBloNegIndHi = bwareaopen(ImBloNegIndHi,voxelsizemin,8);
230  ind_neg_hi = find(ImBloNegIndHi);
231end
232
233% Handle clims for blobs and anatomical image -----------
234if ~isempty(blobcmin)
235  ImBlob(ImBlob<blobcmin) = blobcmin;
236  minT = blobcmin;
237end
238if ~isempty(blobcmax)
239  ImBlob(ImBlob>blobcmax) = blobcmax;
240  maxT = blobcmax;
241end
242ImBlob=(ImBlob-min(ImBlob(:)));
243
244if deactivations
245  if ~isempty(blobnegcmin)
246    ImBlobNeg(ImBlobNeg<blobnegcmin) = blobnegcmin;
247    minTneg = blobnegcmin;
248  end
249  if ~isempty(blobnegcmax)
250    ImBlobNeg(ImBlobNeg>blobnegcmax) = blobnegcmax;
251    maxTneg = blobnegcmax;
252  end
253  ImBlobNeg=(ImBlobNeg-min(ImBlobNeg(:)));
254end
255
256if ~isempty(anatcmin)
257  ImAnat(ImAnat<anatcmin) = anatcmin;
258end
259if ~isempty(anatcmax)
260  ImAnat(ImAnat>anatcmax) = anatcmax;
261end
262
263% Construct indexed image -------------------------------
264ImBlob = round(ImBlob./(maxT-minT)*255);
265if deactivations
266  ImBlobNeg = round(ImBlobNeg./(maxTneg-minTneg)*255);
267  ImBlobNeg = abs(ImBlobNeg-256);
268end
269ImAnat = round(ImAnat./max(ImAnat(:))*255);
270ImRes = ImAnat;
271if deactivations
272  ImRes(ind_neg_hi) = ImBlobNeg(ind_neg_hi)+256;
273  ImRes(ind_hi) = ImBlob(ind_hi)+2*256;
274else
275  ImRes(ind_hi) = ImBlob(ind_hi)+256;
276end
277
278% Construct joint colormap
279if deactivations
280  tmp = eval([blobcmap,'(256)']);
281  %tmp2 = jet(512);
282  %tmp2=tmp2(1:256,:);
283  tmp2 = eval([blobnegcmap,'(256)']);
284  ImBlobColormap = [tmp2;tmp];
285else
286  ImBlobColormap=eval([blobcmap,'(256)']);
287end
288ImAnatColormap=eval([anatcmap,'(256)']);
289StackedColormap = [ImAnatColormap;ImBlobColormap];
290
291if nargout>0
292  im = ImRes;
293  cmap = StackedColormap;
294  im_rgb = ind2rgb(im,cmap);
295  if deactivations
296     minmaxT = [minT maxT -maxTneg -minTneg];
297  else
298    minmaxT = [minT maxT];
299  end
300end
301
302
Note: See TracBrowser for help on using the repository browser.

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