-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdsInterp.m
More file actions
39 lines (24 loc) · 881 Bytes
/
Copy pathdsInterp.m
File metadata and controls
39 lines (24 loc) · 881 Bytes
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
function dsInterped = dsInterp(dsIn, threshold)
% Nearest neighbor interpolation of metal region
[R, C]=size(dsIn);
[X,Y]=meshgrid(1:C, 1:R);
metalMask = dsIn >= threshold;
metalMask=imdilate(metalMask,strel('disk',1,8));
metalMask=imdilate(metalMask,strel('disk',1,8));
% metalMask=imerode(metalMask,strel('disk',1,8));
metalIndxs = find( metalMask );
nonmetalIndxs = find( ~metalMask );
dsInterped=dsIn;
minIndxs = zeros(1,length(metalIndxs));
parfor mIndx=1:length(metalIndxs)
if(mod(mIndx,10)==0)
disp(['Interping ' num2str(mIndx) ' of ' num2str(length(metalIndxs)) ' points']);
end
dists = sqrt( ...
( X(metalIndxs(mIndx)) - X(nonmetalIndxs) ).^2 + ...
( Y(metalIndxs(mIndx)) - Y(nonmetalIndxs) ).^2 );
[~,minIndx]=min(dists(:));
minIndxs(mIndx) = nonmetalIndxs(minIndx);
end
dsInterped(metalIndxs)= dsIn(minIndxs);
end