How can I inpaint/interpolate data from an area that was masked during an experiment?
68 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alex
el 2 de Sept. de 2025 a las 11:31
Respondida: William Rose
el 2 de Sept. de 2025 a las 21:12
I have included an image, so that you can get a feel for the data. I have tried a number of approaches, mainly using code from chatgpt as I'm not great at coding. The best I have found so far is to do column and row pass envelopes, but a more radial approach would be better. Every time I have tried this though I have just ended up with a strange sphere under the main peak.
I would really appreciate if anyone has any suggestions in MATLAB about functions that would be useful to either automatically mask the gridded sections or interpolate well using neighbouring info from the unmasked regions?

7 comentarios
William Rose
el 2 de Sept. de 2025 a las 19:52
The z-values in the data file range from -71 nm to +745 nM. Are thenegative values measurement errors?
Respuesta aceptada
Stephen23
el 2 de Sept. de 2025 a las 11:57
Try downloading this: https://www.mathworks.com/matlabcentral/fileexchange/4551-inpaint_nans
Más respuestas (1)
William Rose
el 2 de Sept. de 2025 a las 21:12
Examine the data graphically to get some insight into the issues.
x=((1:380)-0.5)/380; % x values from Exampledata.zip
y=x; % y values from Exampledata.zip
z=load('zdata'); % z values from Exampledata.zip
z=z.z; % get vector from the structure variable
Z=reshape(z,[380,380]); % reshape vector to matrix
figure
subplot(211), surf(x,y,Z,'EdgeColor','none')
xlabel('X'); ylabel('Y'); zlabel('Z'); grid on % default view
subplot(223), surf(x,y,Z,'EdgeColor','none')
xlabel('X'); ylabel('Y'); zlabel('Z'); grid on; view(0,0) % X-Z view
subplot(224), surf(x,y,Z,'EdgeColor','none')
xlabel('X'); ylabel('Y'); zlabel('Z'); grid on; view(90,0) % Y-Z view
Zoom in on the X-Z and Y-Z views.
figure;
subplot(211), surf(x,y,Z,'EdgeColor','none')
xlabel('X'); ylabel('Y'); zlabel('Z'); grid on; view(0,0); % X-Z view
xlim([0.3,0.7]); zlim([-1e-7,1e-7])
subplot(212), surf(x,y,Z,'EdgeColor','none')
xlabel('X'); ylabel('Y'); zlabel('Z'); grid on; view(90,0); % Y-Z view
ylim([0.3,0.7]); zlim([-1e-7,1e-7])
The plot shows that the surface profile at the edge of the masked region is sloped, and not a sharp discontinuity. This means it is not obvious which points should be replaced with NaNs, since the edge of the masked region is somewhat gradual.
The code below generates another view, to reveal the street and avenue locations. Clip the Z values to the range +-1e-8 before plotting.
Zclipped=max(min(Z,1e-8),-1e-8);
figure; surf(x,y,Zclipped,'EdgeColor','none')
xlabel('X'); ylabel('Y'); zlabel('Z');
axis equal; view(0,90); colorbar % X-Y view
The figure above shows that the avenue and street widths are not the same everywhere.
You said in your reply to @Stephen23 that you used inpaint_nans by @John D'Errico and that "It's working okay, but some parts of the masked grid are creeping and causing some imperfections." Try removing more points on the edges of the streets and avenues, based on the plots above and your own judgement. You may also find it useful to convert all negative values to zeros, using min(), before using inpaint_nans.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!