warping error - array is wrong size or shape

6 次查看(过去 30 天)
Hi,
I'm trying to warp an image over the surface formed by my X,Y,Z, data but I'm getting the following error. The warp examples on the MATLAB website work for me (https://www.mathworks.com/help/images/ref/warp.html), but I can't understand why it doesn't work for my X,Y,Z data. Any help would be greatly appreiated, thanks!
To simplify the code, the matrix double V was obtained from a separate is attached
%% V data is in attached .mat file
[I,map] = imread('forest.tif');
% h=surf(V(:,1),V(:,2),V(:,3))
warped=warp(V(:,1),V(:,2),V(:,3),I);
Error:
Warning: Error creating or updating Surface
Error in value of property ZData
Array is wrong shape or size
  1 个评论
Iuliu Ardelean
Iuliu Ardelean 2021-1-12
编辑:Iuliu Ardelean 2021-1-12
Hi Tom, I think X,Y,Z in warp(X,Y,Z,I) have to represent a surface, i.e. you might need to use meshgrid.

请先登录,再进行评论。

回答(1 个)

Rupesh
Rupesh 2024-2-15
编辑:Rupesh 2024-2-29
Hi Tom,
I have gone through your example and understand that error message that you are encountering indicates that dimensions of X,Y,Z data do not match the dimensions of Image " I " that you are trying to wrap onto the surface ,the warp function expects X,Y and Z to be 2D matrices that define a grid of Points over which image will be displayed . The potential fix of the solution can be done in below 3 steps as follows:
  • you might need to convert input V matrix into three 2D matrices X,Y and Z that represent a grid of points. If your data is not already in a grid format, you might need to use functions like "meshgrid" or "griddata" to create a grid from scattered data.
  • If V represents a uniform grid, then you can simply reshape the columns into the correct 2D format.
  • The image I must be the same size as the X, Y, and Z matrices, or it will be stretched to fit.
Below is modified version of the given code with slight modifications to get desired output .
% Load V from the V.mat file
load('Vmatrix.mat', 'V');
% Check the size of V to understand its structure
disp(size(V));
% Load the image
[I, map] = imread('forest.tif');
% Assuming V is a matrix with size 2480x3 where each row is a point (x, y, z)
% You need to create a grid for X, Y, Z
x = V(:,1);
y = V(:,2);
z = V(:,3);
% Create a grid - the range and resolution of the grid will depend on your specific data
[Xq, Yq] = meshgrid(linspace(min(x), max(x), size(I, 2)), linspace(min(y), max(y), size(I, 1)));
% Interpolate Z data onto the grid
Zq = griddata(x, y, z, Xq, Yq, 'linear');
figure
% Now warp the image over the surface
warp(Xq, Yq, Zq, I,map);
Below is the output that you can expect after execution of above code .
You can refer to following documents for more information regarding Image Wrap Operations for better understanding.
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Geometric Transformation and Image Registration 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by