フィルターのクリア

Deformation of surface induced by Cubic interpolation

7 ビュー (過去 30 日間)
Julien Maxime
Julien Maxime 2022 年 10 月 5 日
回答済み: Nipun 2023 年 12 月 15 日
Hello,
I am currently interpolating heatmap-style data overtime to make 3D surfaces. On the left are raw data and right interpolated ones (surface on top and colorfill on bottom).
As seen in the left image, using the 'linear' method works fine but data still look too sharp for me. However, when trying the 'cubic' method, it deforms the geometry of the dataset.
It is problem solvable with cubic interpolation ? I tried others methods but none other are suited to my data.
Thank you very much,
  2 件のコメント
John D'Errico
John D'Errico 2022 年 10 月 5 日
First, you have a noisy surface. accept that as a fact.
Next, what does interpolation do? It MUST follow the data points exactly, as that is the meaning of interpolation. But, in order to be also smooth, this means it will often do strange things, in order to be both smooth, and have fidelity to pass EXACTLY through each point in the surface.
An example of the above is what a cubic spline interpolant does, when faced with a sharp transition. This is a worst case. You will see ringing, so oscillations much like what is called Gibbs phenomena. So you often don't want to be using a higher order interpolant to fit noisy data anyway, and that is what a spline is, a higher order interpolant.
As far as changing the geometry, I assume you mean the surface has a different boundary shape. And this tells me you seem to be using interp2 to perform the interpolation, where you filled the corners where you lack data with NaNs. This is just a guess, and I lack any data or see any code.
Julien Maxime
Julien Maxime 2022 年 10 月 5 日
Yes I know i have noisy data. And yes I indeed use the interp2 function with the 'cubic' method.
By the way the method named 'spline' gives me abberant data which is normal as my range cross over 0. But I could not find what the 'cubic' function is exactly.
The goal is of course not to interpolate NaN data and respect edge shape. In linear it works fine but then am I doomed to edge deformation when using cubic method ? What do you advise me then ?
I give you some relevant part of code with comments. It corresponds to the initialisation of uifigure.
"data" is the 3D matrix comprising series of heatmaps with respect to frame number (z dimension).
%Intialisation interpolation 2nd layer data (Frame #2)
[Xq,Yq] = meshgrid(1:0.1:12);
Vq = interp2(data(:,:,2),Xq , Yq, 'linear');
%Creation of surface plot of InterP data (Initialisation)
heatObj1 = surf(ax1, Xq, Yq, Vq, "EdgeColor", 'none');
set(ax1.Title,'String',sprintf('Electrode Fluorescence Interpolated Surface - Frame 2'));
set(ax1,'Ydir','reverse'); %Same angle as raw heatmap
%Fixation des valeurs de z
zlim(ax1,[-400 300]);
%Fixation de la range de couleur
clim(ax1,[-400 300]);
%Creation of colorfill plot of InterP data (Initialisation)
heatObj2 = pcolor(ax2, Xq, Yq, Vq);
set(ax2.Title,'String',sprintf('Electrode Fluorescence Interpolated Heatmap - Frame 2'));
set(ax2,'Ydir','reverse'); %Same angle as raw heatmap
set(ax2,'Color','k')
set(heatObj2,'edgecolor','none')
colormap(ax2, turbo)
zlim(ax2,[-400 300]);
clim(ax2,[-400 300]);
%Creation of surface plot of Raw data (Initialisation)
heatObj3 = surf(ax3, data(:,:,2));
set(ax3,'Ydir','reverse'); %Same angle as raw heatmap
set(ax3.Title,'String',sprintf('Electrode Fluorescence Raw Surface - Frame 2'));
%Fixation des valeurs de z
zlim(ax3,[-400 300]);
%Fixation de la range de couleur
clim(ax3,[-400 300]);
%Creation of heatmap plot of Raw data (Initialisation)
heatObj4 = heatmap(uip, data(:,:,2),'Colormap', turbo,'CellLabelColor', 'none','ColorLimits', [-400 300]);
heatObj4.Title = 'Electrode Fluorescence Raw Heatmap - Frame 2';

サインインしてコメントする。

回答 (1 件)

Nipun
Nipun 2023 年 12 月 15 日
Hi Julien,
I understand that you wan to know about interpolating data for 3D surface visualization in MATLAB. The choice of interpolation method can significantly impact the appearance of the resulting surfaces.
When using the 'linear' method, the interpolation is piecewise linear between data points, resulting in sharp transitions. On the other hand, the 'cubic' method often provides smoother surfaces, but it can also introduce unintended deformations, especially if the data is not well-behaved.
There are a few tips that may help you:
MATLAB provides several interpolation methods. In addition to 'linear' and 'cubic,' you might want to try 'nearest,' 'v4,' 'spline,' or 'pchip' methods to see if any of them provide a better balance between smoothness and accuracy.
F = scatteredInterpolant(x, y, z, 'cubic');
[Xq, Yq] = meshgrid(linspace(min(x), max(x), 100), linspace(min(y), max(y), 100));
Zq = F(Xq, Yq);
If your data has a wide range of values, normalization might help in achieving better interpolation results. You can normalize your data before interpolation and then reverse the normalization on the interpolated results.
x_normalized = (x - min(x)) / (max(x) - min(x));
y_normalized = (y - min(y)) / (max(y) - min(y));
F_normalized = scatteredInterpolant(x_normalized, y_normalized, z, 'cubic');
You might also consider using different visualization techniques as follows
figure;
subplot(1,2,1);
contour(Xq, Yq, Zq);
title('Contour Plot');
subplot(1,2,2);
mesh(Xq, Yq, Zq);
title('Mesh Plot');
Hope this helps.
Regards,
Nipun

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by