source: aedes_copy_roi.m

Last change on this file was 80, checked in by tjniskan, 9 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: 3.6 KB
Line 
1function ROI = aedes_copy_roi(ROI,roi_label,dir_ind,slice_ind,vol_ind,data_ind,copytype)
2% AEDES_COPY_ROI - Copy ROI in X, Y, or Z direction
3%   
4%
5% Synopsis:
6%
7% Description:
8%
9% Examples:
10%
11% See also:
12%
13
14% This function is a part of Aedes - A graphical tool for analyzing
15% medical images
16%
17% Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi>
18%
19% Department of Physics, Department of Neurobiology
20% University of Kuopio, FINLAND
21%
22% This program may be used under the terms of the GNU General Public
23% License version 2.0 as published by the Free Software Foundation
24% and appearing in the file LICENSE.TXT included in the packaging of
25% this program.
26%
27% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29
30
31% Check input arguments
32if nargin<5
33  error('Too few input arguments')
34end
35
36% Return immediately if ROI is an empty structure
37% or if ROI is not structure type
38if isempty(ROI) || ~isstruct(ROI)
39  return
40end
41
42%% Check if ROI is for normal or mixed type data
43if length(ROI(1).voxels)>1
44  isMixedType = true;
45else
46  isMixedType = false;
47end
48
49
50% Check if the ROI is identied as an index
51% or label
52if ischar(roi_label)
53  roi_ind = find(strcmp({ROI(:).label},roi_label));
54 
55  if isempty(roi_ind)
56    error(['ROI labeled "' roi_label '" was not found!'])
57    return
58  end
59 
60elseif isnumeric(roi_label)
61  roi_ind = roi_label;
62  if roi_ind<1 || roi_ind>length(ROI)
63    error('ROI index exceeds ROI dimensions.')
64    return
65  end
66else
67  error('Second input argument not valid!')
68  return
69end
70
71if isMixedType
72  dir_ind = 3;
73 
74  % Current ROI size
75  currentRoiSz = size(ROI(roi_ind).voxels{data_ind});
76  currentRoiSlice = ROI(roi_ind).voxels{data_ind};
77 
78  % Copy "current slice" of the selected ROI
79  for ii=1:length(ROI(roi_ind).voxels)
80    if any(ii==slice_ind)
81      % Resize the ROI slice before adding
82      sz = size(ROI(roi_ind).voxels{ii});
83      newRoiSlice = imresize(currentRoiSlice,sz,'nearest');
84      newRoiInd = find(newRoiSlice);
85      if strcmpi(copytype,'append')
86        ROI(roi_ind).voxels{ii}(newRoiInd)=true;
87      else
88        ROI(roi_ind).voxels{ii}(:,:)=false;
89        ROI(roi_ind).voxels{ii}(newRoiInd)=true;
90      end
91    end
92  end
93 
94else
95  if dir_ind==1
96    dir_ind=3;
97  elseif dir_ind==3
98    dir_ind=1;
99  end
100 
101  % Calculate the projection that is copied
102  roi_sz=size(ROI(roi_ind).voxels{1}(:,:,:,vol_ind));
103  %tmp=zeros(sz([1 2 3]~=dir_ind),'uint8');
104  %keyboard
105  if dir_ind == 4
106        tmp=find(ROI(roi_ind).voxels{1}(:,:,:,vol_ind)>0);
107        [r,c,x]=ind2sub(size(ROI(roi_ind).voxels{1}(:,:,:,vol_ind)),...
108          tmp);
109  else
110        [r,c]=find(squeeze(sum(ROI(roi_ind).voxels{1}(:,:,:,vol_ind),dir_ind))>0);
111  end
112
113  % Generate indices
114  lr = length(r);
115  r=repmat(r,length(slice_ind),1);
116  c=repmat(c,length(slice_ind),1);
117  if dir_ind==4
118        x=repmat(x,length(slice_ind),1);
119  end
120  slice_ind = slice_ind(:).';
121  slice_ind=repmat(slice_ind,lr,1);
122  slice_ind=slice_ind(:);
123  v=ones(size(slice_ind))*vol_ind;
124 
125 
126  % Copy to slices
127  if dir_ind==3
128    % X direction
129    ind = sub2ind(size(ROI(roi_ind).voxels{1}),r,c,slice_ind,v);
130  elseif dir_ind==2
131    % Y direction
132    ind = sub2ind(size(ROI(roi_ind).voxels{1}),r,slice_ind,c,v);
133  elseif dir_ind==1
134    % Z direction
135    ind = sub2ind(size(ROI(roi_ind).voxels{1}),slice_ind,r,c,v);
136  elseif dir_ind==4
137        % V direction
138        ind = sub2ind(size(ROI(roi_ind).voxels{1}),r,c,x,slice_ind);
139  end
140 
141  if strcmpi(copytype,'append')
142    ROI(roi_ind).voxels{1}(ind) = true;
143  else
144    ROI(roi_ind).voxels{1}(:) = false;
145    ROI(roi_ind).voxels{1}(ind) = true;
146  end
147end
148
149
Note: See TracBrowser for help on using the repository browser.

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