source: an2_copy_roi.m @ 41

Last change on this file since 41 was 39, checked in by tjniskan, 11 years ago
  • Added "Recent Files" quick access menu in File-menu
  • Fixed a bug in plugins/copy_data_to_workspace.m that made writing a

new name for a variable difficult

  • Fixed a bug in the file prefix editbox in an2_export_gui.m
  • Changed references to Analyze 2.0 in all license notices to Aedes.

The name change should now be complete...

M an2_export_gui.m
M an2_cellsprintf.m
M an2_calc_wait.m
M an2_check_file_exist.m
M an2_iseven.m
M an2_cellwrite.m
M an2_wbar.m
M an2_rot3d.m
M an2_readfdf.m
M an2_revision.m
M an2_viewprocpar.m
M an2_checkcthdr.m
M an2_readprocpar.m
M an2_fitmaps.m
M an2_read_nifti.m
M an2_data_read.m
M an2_resviewer.m
M an2_maptool.m
M aedes.m
M an2_res2table.m
M an2_copy_roi.m
M plugins/save_roi_as_mask.m
M plugins/write_difference_images.m
M plugins/plot_profile.m
M plugins/calculate_t2_map.m
M plugins/calculate_t1r_map.m
M plugins/view_kspace.m
M plugins/copy_data_to_workspace.m
M plugins/take_snapshot.m
M an2_inputdlg.m
M an2_roi_copy_gui.m
M an2_readctdata.m
M an2_readfid.m
M an2_readfidprefs.m
M an2_readtab.m
M an2_check_updates.m
M an2_killfigs.m
M an2_roi_stats.m
M an2_saveres.m
M an2_rotateflip.m
M an2_juigetfiles.m
M an2_gui_defaults.m
M an2_editstack.m
M an2_update.m
M an2_write_nifti.m

File size: 3.3 KB
Line 
1function ROI = an2_copy_roi(ROI,roi_label,dir_ind,slice_ind,vol_ind,data_ind,copytype)
2% AN2_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, (or 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  [r,c]=find(squeeze(sum(ROI(roi_ind).voxels{1}(:,:,:,vol_ind),dir_ind))>0);
106
107  % Generate indices
108  lr = length(r);
109  r=repmat(r,length(slice_ind),1);
110  c=repmat(c,length(slice_ind),1);
111  slice_ind = slice_ind(:).';
112  slice_ind=repmat(slice_ind,lr,1);
113  slice_ind=slice_ind(:);
114  v=ones(size(slice_ind))*vol_ind;
115 
116  % Copy to slices
117  if dir_ind==3
118    % X direction
119    ind = sub2ind(size(ROI(roi_ind).voxels{1}),r,c,slice_ind,v);
120  elseif dir_ind==2
121    % Y direction
122    ind = sub2ind(size(ROI(roi_ind).voxels{1}),r,slice_ind,c,v);
123  else
124    % Z direction
125    ind = sub2ind(size(ROI(roi_ind).voxels{1}),slice_ind,r,c,v);
126  end
127 
128  if strcmpi(copytype,'append')
129    ROI(roi_ind).voxels{1}(ind) = true;
130  else
131    ROI(roi_ind).voxels{1}(:) = false;
132    ROI(roi_ind).voxels{1}(ind) = true;
133  end
134end
135
136
Note: See TracBrowser for help on using the repository browser.

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