How can I inpaint/interpolate data from an area that was masked during an experiment?

68 visualizaciones (últimos 30 días)
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
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?
Alex
Alex el 2 de Sept. de 2025 a las 20:01
They should be measurement errors, but I think they are negligible enough to be treated that way even if they aren't.

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 2 de Sept. de 2025 a las 11:57
  1 comentario
Alex
Alex el 2 de Sept. de 2025 a las 16:44
Thanks so much for this suggestion! It's pretty much exactly what I'm looking for and has got me much closer to a workable solution

Iniciar sesión para comentar.

Más respuestas (1)

William Rose
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.

Community Treasure Hunt

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

Start Hunting!

Translated by