-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfindxyz.m
63 lines (50 loc) · 1.67 KB
/
findxyz.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
function [ xyzlocations ] = findxyz( mat, varargin )
%findxyz Convert either indexed list or 3D matrix of Logicals to X,Y,Z coordinates
% Outputs an n by 3 matrix where column one is the x coordinate, column
% two is the y coordinate, and so on... If you add the Holo input, there
% will an extra column with the value of Holo at coodinate (x,y,...)
%
xycrop = false;
while ~isempty(varargin)
switch upper(varargin{1})
case 'HOLO'
Holo = [(varargin{2})];
varargin(1:2) = [];
case 'XYCROP'
rect = [(varargin{2})];
xycrop = true;
% rect = [1550-512,2070-1024,1023,1023];
varargin(1:2) = [];
otherwise
error(['Unexpected option: ' varargin{1}])
end
end
if isvector(mat) || isscalar(mat)
idxlist = mat;
matsize = size(Holo);
matdims = ndims(Holo);
else
idxlist = find(mat);
matsize = size(mat);
matdims = ndims(mat);
end
numpart = length(idxlist);
if xycrop == false
rect = [1,1,matsize(2),matsize(1)];
end
xyzlocations(numpart,3) = 0; % makes colums for x,y,z coordinates
for L = 1:numpart
if matdims > 2
xyzlocations(L,3) = ceil(idxlist(L)/(matsize(1)*matsize(2)));
end
xyzlocations(L,2) = rem(rem(idxlist(L),(matsize(1)*matsize(2))),matsize(1));
xyzlocations(L,1) = ceil(rem(idxlist(L),(matsize(1)*matsize(2)))/matsize(1));
end
if exist('Holo','var')
for L = 1:numpart
xyzlocations(L,matdims+1) = Holo(xyzlocations(L,2),xyzlocations(L,1),xyzlocations(L,3));
end
end
xyzlocations(:,2) = xyzlocations(:,2) + rect(2) - 1;
xyzlocations(:,1) = xyzlocations(:,1) + rect(1) - 1;
end