forked from uw-loci/curvelets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetFirstNeighbor.m
58 lines (50 loc) · 1.62 KB
/
GetFirstNeighbor.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
function [ outpt ] = GetFirstNeighbor( mask, idx, visitedList,direction )
% GetFirstNeighbor.m - Find the first contiguous neighbor in the mask file
%
% Inputs
% mask = list [row,col] of foreground pixels in the binary mask created in FIJI
% idx = index of the point around which we will search for a contiguous white pixel
% visitedList = list of pixels we've already checked
%
% Optional Inputs
%
% Outputs
% outpt = first neighbor pixel (row,col)
%
% By Jeremy Bredfeldt Laboratory for Optical and
% Computational Instrumentation 2013
pt = mask(idx,:);
%search points
%YL: fill list in two directions
if direction == 1
npt = [pt(1) pt(2)+1;... %E
pt(1)-1 pt(2)+1;... %NE
pt(1)-1 pt(2);... %N
pt(1)-1 pt(2)-1;... %NW
pt(1) pt(2)-1;... %W
pt(1)+1 pt(2)-1;... %SW
pt(1)+1 pt(2);... %S
pt(1)+1 pt(2)+1]; %SE
elseif direction == 2
npt = [pt(1) pt(2)-1;... %W
pt(1)+1 pt(2)-1;... %SW
pt(1)+1 pt(2);... %S
pt(1)+1 pt(2)+1;... %SE
pt(1) pt(2)+1;... %E
pt(1)-1 pt(2)+1;... %NE
pt(1)-1 pt(2);... %N
pt(1)-1 pt(2)-1]; %NW
end
outpt = idx;
rows = mask(:,1);
cols = mask(:,2);
%check east, northeast, north, northwest, west, southwest, south, then southeast
for i = 1:length(npt)
%find a position in the list that is next to the current one, that we haven't found yet
chkIdx = find(rows == npt(i,1) & cols == npt(i,2),1,'first');
if (~isempty(chkIdx) && visitedList(chkIdx)==0)
outpt = chkIdx;
return;
end
end
end