Interpolation of missing matrix element
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
KSSV
am 1 Nov. 2022
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 Kommentar
DGM
am 1 Nov. 2022
Bearbeitet: DGM
am 1 Nov. 2022
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?
Weitere Antworten (1)
DGM
am 1 Nov. 2022
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 Kommentare
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!