Interpolation of missing matrix element
2 ビュー (過去 30 日間)
古いコメントを表示
Hello, I am trying to interpolate some missing data of my 3x3 matrix,
M = [43.13 0 42.88;0 39.32 0;41.81 0 43.27];
where 0s represent the missing value that I would like to interpolate to fill it in.
I read through interp1-3 command but not so sure on what to do to find a missing values
Please help!
0 件のコメント
採用された回答
KSSV
2022 年 11 月 1 日
M = [43.13 0 42.88;0 39.32 0;41.81 0 43.27];
M(M==0) = NaN
M = fillmissing(M,'linear')
M = fillmissing(M','linear')'
1 件のコメント
DGM
2022 年 11 月 1 日
編集済み: DGM
2022 年 11 月 1 日
Fillmissing() only interpolates/extrapolates columnwise. Since the center column has only a single value, extrapolation fails. While transposing and filling again will clean up the remaining holes, it still means that the center pixel has no influence over any of the filled values.
M = [1 0 1; 0 0 0; 0 1E6 0; 1 0 1];
M(M==0) = NaN;
M = fillmissing(M,'linear')
M = fillmissing(M','linear')'
If there were enough data in the center column to support the default extrapolation behavior, the results would be wildly different.
M = [1 0 1; 0 1E6 0; 0 1E6 0; 1 0 1];
M(M==0) = NaN;
M = fillmissing(M,'linear')
M = fillmissing(M','linear')'
Using fillmissing() seems like it would be valid for columnwise organized data, but if that were the case, would it still make sense to interpolate across columns?
その他の回答 (1 件)
DGM
2022 年 11 月 1 日
I'm sure there are multiple ways, and interpolation may depend on whether this is 2D data or a bunch of independent rows of data. Here are a few things.
I'm not familiar with using fillmissing(), but using it like this doesn't seem right. It fills the holes, but the center pixel has no influence over filling its neighbors.
% above solution
M = [43.13 0 42.88;0 39.32 0;41.81 0 43.27];
M(M==0) = NaN;
M = fillmissing(M,'linear');
M = fillmissing(M','linear')';
imshow(M,[38 44])
If you have IPT, you can use regionfill()
% inpaint with IPT regionfill()
M = [43.13 0 42.88;0 39.32 0;41.81 0 43.27];
mask = M==0;
M = regionfill(M,mask);
imshow(M,[38 44])
If you don't have IPT, you could use John's inpainting tool from the FEX:
% inpaint with inpaint_nans()
M = [43.13 0 42.88;0 39.32 0;41.81 0 43.27];
M(M==0) = NaN;
M = inpaint_nans(M);
imshow(M,[38 44])
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Interpolation of 2-D Selections in 3-D Grids についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!