Changeset 883
- Timestamp:
- 01/04/12 15:50:09 (18 months ago)
- Files:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
MGET/Branches/Jason/PythonPackage/src/GeoEco/Matlab/Functions.matlab/InpaintNaNs.m
r872 r883 1 function B = inpaint_nans2(A, method, maxHoleSize, xEdgesWrap) 1 function [B] = InpaintNaNs(A, method, maxHoleSize, edgesWrap) 2 % InpaintNaNs: inpaint_nans with some additional options. 3 4 % If the caller indicated that the left and right edges wrap, buffer those 5 % edges by 10 cells. Hopefully this will be enough for maxHoleSize to still 6 % work properly. 7 8 if edgesWrap ~= 0 9 buffer = min(10, size(A,2)); 10 A2 = zeros(size(A,1), size(A,2) + buffer*2, class(A)); 11 A2(:, 1:buffer) = A(:, (size(A,2)-buffer+1):size(A,2)); 12 A2(:, (buffer+1):(buffer+size(A,2))) = A; 13 A2(:, (buffer+size(A,2)+1):size(A2,2)) = A(:, 1:buffer); 14 else 15 A2 = A; 16 end 17 18 % Call inpaint_nans. If maxHoleSize was provided, only fill holes up to 19 % that size with what inpaint_nans returns (leave the others as NaN). 20 2 21 if maxHoleSize >= 1 3 L = bwlabel(isnan(A), 4); 22 C = inpaint_nans(A2, method); 23 L = bwlabel(isnan(A2), 4); 4 24 STATS = regionprops(L, 'Area'); 5 B = A; 6 B(ismember(L, find(arrayfun(@(x) x.Area >= maxHoleSize, STATS)))) = inpaint_nans(A, method); 25 H = ismember(L, find(arrayfun(@(x) x.Area <= maxHoleSize, STATS))); 26 B2 = A2; 27 B2(H) = C(H); 7 28 else 8 B = inpaint_nans(A, method); 29 B2 = inpaint_nans(A2, method); 30 end 31 32 % If the caller indicated that the left and right edges wrap, extract the 33 % output array from within the buffer. 34 35 if edgesWrap ~= 0 36 B = B2(:, (buffer+1):(size(B2,2)-buffer)); 37 else 38 B = B2; 39 end 40 9 41 end 10 42 … … 460 492 % A was when we came in. 461 493 B=reshape(B,n,m); 462 494 end 463 495 464 496 % ==================================================== … … 526 558 neighbors_list=[]; 527 559 end 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 560 end
