I am having a problem in applying 3d Scattered interpolation in my relative code.

1 次查看(过去 30 天)
I am having 150 images which are in a stack and i am getting a 3d volume from that slices but the problem is that there i have used the linear interpolation and i want to do it with that 3d scattered interpolation. I am sharing my code here need help.
clc;
close all;
clear
%% Set folders
addpath('./Images1','./Functions')
%% Get names
data = struct2cell(dir("Images1/*.jpg"));
names = data(1,:);
%% Read and save images
imgs = [];
for i = 1:size(names,2)
clc;
fprintf('Reading image # %i \n',i)
% Read image and convert it from RGB to gray
imgs = cat(3,imgs,rgb2gray(imread(names{i})));
end
x_size = (1:1:size(imgs,3));
y_size = (1:1:size(imgs,2));
z_size = (1:1:size(imgs,1));
%z_size = reshape(z_size,y_size, x_size);
vol = meshgrid(x_size,y_size,z_size);
%% Create zig zag shape
% Locatae images in the volume
new_imgs = zeros(size(imgs,1),round(2*size(imgs,2)),size(imgs,3));
% X locations of the images
x_locs = round(((sin((1:size(imgs,3))/10) + 1)/11)*550)+10;
%%
for i = 1:size(imgs,3)
clc;
fprintf('Moving image %i \n',i)
new_imgs(:,x_locs(i):x_locs(i)+size(imgs,2)-1,i) = imgs(:,:,i);
end
disp('Making interpolation ....')
factor = [0.25 0.5 3]; % Factor in x, y and z planes
x_qsize = (1:1/factor(1):size(new_imgs,1));
y_qsize = (1:1/factor(2):size(new_imgs,2));
z_qsize = (1:1/factor(3):size(new_imgs,3));
F = scatteredInterpolant(x_size(:), y_size(:),z_size(:));
[x_query,y_query,z_query] = meshgrid(x_qsize, y_qsize, z_qsize);
% Make interpolation
% Interpolation method
%% method = 'linear'; % You can change this argument
vol_interp = F(new_imgs,y_query,x_query,z_query);
% Load configurations
load('vol_viewer_configs.mat')
figure;
volshow(vol_interp,config1);
figure;
volshow(vol_interp,config2);
.After running the code i am having an error which says that.
Data Points coordinates have inconsistent dimension.
Please have a look and help if someone can.

回答(1 个)

Nipun
Nipun 2024-4-10
Hi Huzaifa,
I understand that you are facing a dimension incompatible error while interpolating data points.
Based on the give information and the error, I can confirm that the cause of the error are the inputs to the "mesh grid" function.
Consider making the dimensions equal to resolve the error.
Hope this helps.
Regards,
Nipun

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by