-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresizePath.m
More file actions
55 lines (44 loc) · 1.38 KB
/
Copy pathresizePath.m
File metadata and controls
55 lines (44 loc) · 1.38 KB
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
function [path, pathY, pathX] = resizePath(szImg, szImgNew, constants, pathY, pathX)
if nargin < 5
display('requires 5 inputs');
return;
end
%delete paths outside of original image;
pathX = pathX(pathY > 1 & pathY < szImgNew(2));
pathY = pathY(pathY > 1 & pathY < szImgNew(2));
%sort paths
[sortVal sortInd] = sort(pathY,'ascend');
pathX = pathX(sortInd);
pathY = pathY(sortInd)-1; %update subscriptY
%ensure paths are unique
[uniqVal uniqInd] =unique(pathY);
pathY = pathY(uniqInd);
pathX = pathX(uniqInd);
%translate before scaling
pathY = pathY-1;
pathX = pathX-1;
%scale back
%built scaling matrix T
scale = 1/constants.shrinkScale;
T = [scale 0 0; 0 scale 0; 0 0 1];
arr= [pathY; pathX; ones(size(pathY))];
arr = T*arr;
pathY = arr(1,:);
pathX = arr(2,:);
%translate after scaling
pathY = pathY+round(scale/2);
pathX = pathX+round(scale/2);
%resample, use extrap to extrap out of range subscripts.
pathX = round(interp1(pathY,pathX,1:szImg(2),'linear','extrap'));
pathY = 1:szImg(2);
%add front and back segments, so to be compatible with other
%structures.
startSegmentX = 1:pathX(1);
endSegmentX = pathX(end):szImg(1);
startSegmentY = ones([1 numel(startSegmentX)]);
endSegmentY = szImg(2).*ones([1 numel(endSegmentX)]);
pathX = [startSegmentX pathX endSegmentX];
pathY = [startSegmentY pathY+1 endSegmentY];
szImg(2) = szImg(2)+2;
%get indices
path = sub2ind(szImg,pathX,pathY);