data correction

2 次查看(过去 30 天)
Mahmood dandelion
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.

回答(2 个)

Clemens
Clemens 2011-7-4
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 个评论
Mahmood dandelion
thank you
it works.
is there any way to find islands with 2 or more nan cells?
Clemens
Clemens 2011-7-4
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
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 个评论
Wolfgang Schwanghart
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
The last line of code should be
demcorrected = roifill(dem,imdilate(I,ones(3)));

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by