data correction
2 views (last 30 days)
Show older comments
i have a matrix of topographic data. 1356*3039 there are some NaN cells in this matrix that I should remove them. for example like this: 928 926 932 939 970 938 937 936 940 965 949 931 940 928 957 1000 984 NaN 988 987 1108 1094 1121 1117 1068 1253 1285 1313 1226 1169
I want to create a rule to detect such cells and fill them with an interpolation of neighbor cells.
I can not use isnan function for all my data because this is a earth sea topographic data and earth data are also NaN.
0 Comments
Answers (2)
Clemens
on 4 Jul 2011
well in some way you will have to use isnan. You could use bwconncomp to find "lonely" Nans. Like in this example:
%%create some sample data
data = rand(10); % make a random sample
data(data>0.9) = NaN; % create some nans
data(1:6,1:6) = NaN; % make an island
c = bwconncomp(isnan(data))
s = cellfun(@numel,c.PixelIdxList)
single_nan_ind = s==1
single_nans = cellfun(@(x) ind2sub(x,size(data)),c.PixelIdxList(single_nan_ind),'UniformOutput',false)
The ones you are looking for would be in single_nans.
2 Comments
Clemens
on 4 Jul 2011
Sure just fix the line:
single_nan_ind = s==1
this finds all groups with just one.
So single_nan_ind = s>5 would find islands with more than 5 nans.
I think you get the idea.
Wolfgang Schwanghart
on 3 Jul 2011
Hi,
you can identify the NaNs using the function isnan.
I = isnan(dem); % where dem is the digital elevation model
The inpaint function by Damian Garcia can be used to fill the gaps.
Cheers, W.
3 Comments
Wolfgang Schwanghart
on 4 Jul 2011
Well, then use isnan and brush the data such that only regions of nans remain that are smaller than a specified number of cells (k).
k = 1;
I = isnan(dem);
I = xor(bwareaopen(I,k+1),I);
demcorrected = roifill(dem,I);
I didn't try it since I just have Matlab not at hand, but it should work.
Wolfgang Schwanghart
on 5 Jul 2011
The last line of code should be
demcorrected = roifill(dem,imdilate(I,ones(3)));
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!