-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathavw_metric.m
43 lines (32 loc) · 1.07 KB
/
avw_metric.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
function [XYZm] = avw_metric(hdr,XYZimg)
% AVW_METRIC - Convert image location from CRS to meters
%
% Useage: XYZm = avw_metric(hdr,XYZimg)
%
% hdr - avw.hdr from avw_hdr_read
% XYZimg - Nx3 matrix of image coordinates
% XYZm - Nx3 matrix of image meter coordinates (not mm)
%
% $Revision: 1.1 $ $Date: 2004/11/12 01:30:25 $
% Licence: GNU GPL, no express or implied warranties
% History: 06/2002, [email protected]
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if isempty(XYZimg), error('XYZimg is empty'); end;
if isempty(hdr), error('hdr is empty'); end;
if size(XYZimg,2) ~= 3,
msg = sprintf('AVW_METRIC: XYZimg must be Nx3 matrix\n');
error(msg);
end
XYZpixdim = double(hdr.dime.pixdim(2:4));
if findstr(hdr.dime.vox_units,'mm'),
fprintf('AVW_METRIC: voxel units: mm\n');
XYZpixdim = XYZpixdim ./ 1000;
end
if findstr(hdr.dime.vox_units,'cm'),
fprintf('AVW_METRIC: voxel units: cm\n');
XYZpixdim = XYZpixdim ./ 100;
end
XYZpixdim = repmat(XYZpixdim,size(XYZimg,1),1);
XYZm = XYZimg .* XYZpixdim;
return