-
Notifications
You must be signed in to change notification settings - Fork 0
/
mni2cor.m
74 lines (70 loc) · 2.7 KB
/
mni2cor.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
function [handles,coordinate_voxels ]= mni2cor(mni , T,roi_size, type,handles)
% function coordinate = mni2cor(mni, T)
% convert mni coordinate to matrix coordinate
%
% mni: a Nx3 matrix of mni coordinate
% T: (optional) transform matrix
% coordinate is the returned coordinate in matrix
%
% caution: if T is not specified, we use:
% T = ...
% [-4 0 0 84;...
% 0 4 0 -116;...
% 0 0 4 -56;...
% 0 0 0 1];
%
%
try
coordinate_voxels = [];
if isempty(mni )
coordinate_voxels = [];
return;
end
if isempty(T)
T = ...
[-4 0 0 84;...
0 4 0 -116;...
0 0 4 -56;...
0 0 0 1];
end
% mni=[0 0 0; 30 30 0]
nn=floor(roi_size(1)/2);
nn1=floor(roi_size(2)/2);
nn2=floor(roi_size(3)/2);
coordinate =[mni(:,1) mni(:,2) mni(:,3) ones(size(mni,1),1)]*(inv(T))';
coordinate(:,4) = [];
coordinate = round(coordinate);
handles.b.roi.image_coordinate=coordinate;
coordinate_voxels=zeros(handles.b.pre.normalization.mean_VOI.dim(1)*handles.b.pre.normalization.mean_VOI.dim(2)*handles.b.pre.normalization.mean_VOI.dim(3),1);
handles.b.roi.mask_vox_ss= zeros(handles.b.pre.normalization.mean_VOI.dim(1)*handles.b.pre.normalization.mean_VOI.dim(2)*handles.b.pre.normalization.mean_VOI.dim(3),size((handles.b.roi.MNI),1));
if strcmp(type,'Sphere')
for iin=1:size(coordinate,1)
[xx ,yy, zz] = meshgrid(1:handles.b.pre.normalization.mean_VOI.dim(2),1:handles.b.pre.normalization.mean_VOI.dim(1),1:handles.b.pre.normalization.mean_VOI.dim(3));
vv = sqrt((xx-coordinate(iin,2)).^2+(yy-coordinate(iin,1)).^2+(zz-coordinate(iin,3)).^2)<=floor(roi_size(1)/2);
for ini=1:handles.b.pre.normalization.mean_VOI.dim(3)
voxels(:,:,ini)=rot90(vv(:,:,ini),1);
% if sum(sum(vv(:,:,ini)))>0
% ini
% figure, imshow(vv(:,:,ini),[0 4])
% figure, imshow(voxels(:,:,ini),[0 4])
% end
end
coordinate_voxels (voxels(:)>0)=iin;
handles.b.roi.mask_vox_ss(:,iin)=(vv(:)>0);
clear voxels
end
elseif strcmp(type,'Cube')
for iin=1:size(coordinate,1)
voxels=zeros(handles.b.pre.normalization.mean_VOI.dim(1),handles.b.pre.normalization.mean_VOI.dim(2),handles.b.pre.normalization.mean_VOI.dim(3));
xx= coordinate(1,1)-nn:1:coordinate(1,1)+nn ;
yy= coordinate(1,2)-nn1:1:coordinate(1,2)+nn1 ;
zz= coordinate(1,3)-nn2:1:coordinate(1,3)+nn2 ;
comb_voxel=combvec(xx,yy,zz);
voxels(comb_voxel(1,:),comb_voxel(2,:),comb_voxel(3,:))=1;
coordinate_voxels (voxels >0)=iin;
handles.b.roi.mask_vox_ss(:,iin)=(voxels(:)>0);
end
end
catch ME
handles=error_log_display(handles,ME);
end