forked from emmay78/mEMbrain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvsvi_to_vsseg.m
101 lines (73 loc) · 3 KB
/
vsvi_to_vsseg.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
function [] = vsvi_to_vsseg(miplevel, layernr, seglayer, annlayer, srcannlayer, ...
x_init, x_end, y_init, y_end, z_init, z_end,...
locationMethod, tileSize, threshold)
immediateflag = 0;
requestloadflag = 1;
vast = evalin('base','vast');
vast.setapilayersenabled(1)
if strcmp(locationMethod,'RANDOM')
vinfo = vast.getinfo();
size_x = double(vinfo.datasizex);
size_y = double(vinfo.datasizey);
size_z = double(vinfo.datasizez);
if ~exist('i_init', 'var') || isempty(x_init)
x_init = 0;
end
if ~exist('i_final', 'var') || isempty(x_end)
x_end = size_x-1;
end
if ~exist('j_init', 'var') || isempty(y_init)
y_init = 0;
end
if ~exist('j_final', 'var') || isempty(y_end)
y_end = size_y-1;
end
if ~exist('z_init', 'var') || isempty(z_init)
z_init = 0;
end
if ~exist('z_final', 'var') || isempty(z_end)
z_end = size_z-1;
end
P0 = [x_init, y_init, z_init]
P1 = [x_end, y_end, z_end]
N = 300; % Sample 300 coordinates
xx=randi([P0(1)+tileSize+1 P1(1)-tileSize-1], N, 1);
yy=randi([P0(2)+tileSize+1 P1(2)-tileSize-1], N, 1);
zz=randi([P0(3) P1(3)], N, 1);
elseif strcmp(locationMethod,'FromVSSANOOFILE')
annlayer_sourceCoordinates = srcannlayer;
vast.setselectedapilayernr(annlayer_sourceCoordinates)
[aonodedatac, ~] = vast.getaonodedata();
xx=aonodedatac(:,6);
yy=aonodedatac(:,7);
zz=aonodedatac(:,8);
N = numel(xx);
end
W = ceil(tileSize/2)/2^miplevel;
for icoord=1:N
coords = [xx(icoord) yy(icoord) zz(icoord)];
[~] = vast.setselectedapilayernr(seglayer);
J = vast.getsegimageRLEdecoded(miplevel,coords(1)-tileSize,coords(1)+tileSize-1,coords(2)-tileSize,coords(2)+tileSize-1,coords(3),coords(3),immediateflag,requestloadflag);
while (J(:) > 0)
coords(1)=randi([P0(1)+tileSize+1 P1(1)-tileSize-1],N,1);
coords(2)=randi([P0(2)+tileSize+1 P1(2)-tileSize-1],N,1);
coords(3)=randi([P0(3) P1(3)],N,1);
J = vast.getsegimageRLEdecoded(miplevel,coords(1)-tileSize,coords(1)+tileSize-1,coords(2)-tileSize,coords(2)+tileSize-1,coords(3),coords(3),immediateflag,requestloadflag);
end
xx(icoord) = coords(1);
yy(icoord) = coords(2);
zz(icoord) = coords(3);
[emimage,~] = vast.getemimage(layernr,miplevel,coords(1)-tileSize,coords(1)+tileSize-1,coords(2)-tileSize, coords(2)+tileSize-1,coords(3),coords(3),immediateflag,requestloadflag);
K = zeros(size(emimage),'uint8');
K(emimage<threshold)=1;
K(emimage>=threshold)=2;
I = zeros(size(emimage),'uint8');
I(emimage>=threshold)=2;
% I(:,[1 2 y_end-1 y_end]) = K(:,[1 2 end-1 end]);
% I([1 2 end-1 end],:) = K([1 2 end-1 end],:);
[~] = vast.setselectedapilayernr(seglayer)
[~] = vast.setsegimageRLE(miplevel,coords(1)-W,coords(1)+W-1,coords(2)-W,coords(2)+W-1,coords(3),coords(3),I);
[~] = vast.setselectedapilayernr(annlayer)
vast.addaonode(coords(1),coords(2),coords(3));
end
end