Not able to interpolate the corners of figure using ScattteredInterpolation function

2 views (last 30 days)
Sangani Prithvi on 5 Nov 2021
Edited: Walter Roberson on 2 Jul 2024
I have a data which is scattered and I want to regularise the data using ScatterredInterpolation function. The point cloud, I'm working is a square tube(rawfigure attached). When I try to regularise the data using ScatterredInterpolation, I'm getting a figure something like this (transformedfig attached), which has large undulations at the corners of the tube (it is supposed to be smooth edge like in the 'rawfigure'). Please let me know what could be the problem and solution.
code which I'm using is,
CTP = [R theta Y]; %.mat file attached
O_x = 1.5940;
O_z = -66.2657;
max_y = max(Y);
min_y = min(Y);
F = scatteredInterpolant(CTP(:,2), CTP(:,3), CTP(:,1)); %Interpolation funcntion for "R"
Xq = 0:4*pi()/(180):2*pi(); %mesh in x direction
Yq = min_y:4:max_y; %mesh in y direction
[XQ, YQ] = meshgrid(Xq, Yq);%meshgrid with the predefined size
ZQ = F(XQ, YQ); %"R" values for the meshgrid
[m n] = size(XQ);
for i = 1:n:n*(m)
C([i:i+(n-1)],[1:3]) = [XQ(((n-1)+i)/n,:)' YQ(((n-1)+i)/n,:)' ZQ(((n-1)+i)/n,:)'];
end
X1 = -C(:,3).*cos(C(:,1))+O_x; %Reverse transform to cartesian coordinates
Z1 = C(:,3).*sin(C(:,1)) + O_z; %Reverse transform to cartesian coordinates
Y1 = C(:,2); %Reverse transform
P1 = [X1 Y1 Z1]; %arranging cartesian coordinates
Pc = pointCloud(P1);
pcshow(Pc)
Thanks,

prabhat kumar sharma on 2 Jul 2024
Edited: prabhat kumar sharma on 2 Jul 2024
Hello, Sangani
I recognize that when you use scatteredInterpolant, you will encounter undulations at the corners of your square tube. Your mesh grid's resolution and interpolation technique may be to blame for this. You might attempt the following actions to obtain smoother edges:
1.Switch up your interpolation technique: You can provide various interpolation techniques, including "natural," "linear," and "nearest," using the scatteredInterpolant function. 'Natural' could produce more polished results.
2.Raising the mesh's resolution Smoother edges can be attained by improving the mesh grid's resolution.
3.Use a smoothing technique: To lessen undulations, you can use a smoothing function on the interpolated data after interpolation.
fields = fieldnames(data);
CTP = data.(fields{1});
R = CTP(:, 1);
theta = CTP(:, 2);
Y = CTP(:, 3);
CTP = [R theta Y];
O_x = 1.5940;
O_z = -66.2657;
max_y = max(Y);
min_y = min(Y);
% Use 'natural' interpolation method for smoother results
F = scatteredInterpolant(CTP(:,2), CTP(:,3), CTP(:,1), 'natural'); % Interpolation function for "R"
% Increase mesh resolution
Xq = 0:pi()/(180):2*pi(); % Finer mesh in x direction
Yq = min_y:1:max_y; % Finer mesh in y direction
[XQ, YQ] = meshgrid(Xq, Yq); % Create meshgrid with the predefined size
ZQ = F(XQ, YQ); % Interpolate "R" values for the meshgrid
% Apply smoothing
ZQ = smoothdata(ZQ, 'gaussian', 5); % Apply Gaussian smoothing
[m, n] = size(XQ);
C = zeros(m*n, 3); % Preallocate C for efficiency
for i = 1:m
C((i-1)*n+1:i*n, :) = [XQ(i, :)' YQ(i, :)' ZQ(i, :)'];
end
% Reverse transform to Cartesian coordinates
X1 = -C(:,3).*cos(C(:,1)) + O_x;
Z1 = C(:,3).*sin(C(:,1)) + O_z;
Y1 = C(:,2);
P1 = [X1 Y1 Z1]; % Arrange Cartesian coordinates
if isempty(P1)
error('Point cloud data is empty.');
end
Pc = pointCloud(P1);
figure;
pcshow(Pc);
title('Point Cloud Display');
xlabel('X');
ylabel('Y');
zlabel('Z');
axis equal;
I hope it helps!
Sangani Prithvi on 2 Jul 2024
Edited: Walter Roberson on 2 Jul 2024
Thank you for your answer. I have used filtering based on 2D Fourier transforms. I have documented the procedure in this article https://doi.org/10.1016/j.jcsr.2024.108625