-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathformatPathsForAnalysis.m
72 lines (53 loc) · 2.61 KB
/
formatPathsForAnalysis.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
function imageLayer = formatPathsForAnalysis(imageLayer)
% transform the path back to orignial space (so when you plot pathY and
% pahtX on the image, it fits with the coordinates of the original image)
params = imageLayer(1).params;
blankImg=ones([numel(imageLayer(1).params.yrange) numel(imageLayer(1).params.xrange)]);
%get image size
if params.isResize(1)
szImg = size(imresize(blankImg,params.isResize(2)));
else
szImg = [size(blankImg)];
end
for i = 1:numel(imageLayer);
%get info
params = imageLayer(i).params;
for j = 1:numel(imageLayer(i).retinalLayers),
%make sure subscript-Y is inbound image, and left shift subscript-y
indValidPath = find(imageLayer(i).retinalLayers(j).pathY ~=1 & ...
imageLayer(i).retinalLayers(j).pathY ~= szImg(2)+2);
pathX = imageLayer(i).retinalLayers(j).pathX(indValidPath);
pathY = imageLayer(i).retinalLayers(j).pathY(indValidPath)-1;
%make sure subscript-ys are unique
[uniqVal uniqInd] = unique(pathY);
pathX = pathX(uniqInd);
pathY = pathY(uniqInd);
%make sure Ys are contiguous
pathYNew = 1:szImg(2);
pathXNew = interp1(pathY,... %original Y
pathX,... %original X, to be interp
pathYNew,... %new Y
'nearest');
if params.isResize(1)
%translate before scaling
pathYNew = pathYNew - 1;
pathXNew = pathXNew - 1;
%scale back
%built scaling matrix T
scale = 1/params.isResize(2);
T = [scale 0 0; 0 scale 0; 0 0 1];
arr= [pathYNew; pathXNew; ones(size(pathY))];
arr = T*arr;
pathYNew = arr(1,:);
pathXNew = arr(2,:);
%translate after scaling
pathYNew = pathYNew+round(scale/2);
pathXNew = pathXNew+round(scale/2);
%resample, use extrap to extrap out of range subscripts.
imageLayer(i).retinalLayers(j).pathYAnalysis = 1:szImg(2)/params.isResize(2);
imageLayer(i).retinalLayers(j).pathXAnalysis = nan([1 szImg(2)/params.isResize(2)]);
%imageLayer(i).retinalLayers(j).pathXAnalysis(params.xrange) = round(interp1(pathYNew,pathXNew,1:szImg(2)/params.isResize(2),'linear','extrap'));
imageLayer(i).retinalLayers(j).pathXAnalysis(:) = round(interp1(pathYNew,pathXNew,1:szImg(2)/params.isResize(2),'linear','extrap'));
end % of resize
end % of j
end % of i