warping error - array is wrong size or shape

7 visualizaciones (últimos 30 días)
Tom Dillon
Tom Dillon el 12 de En. de 2021
Editada: Rupesh el 29 de Feb. de 2024
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 comentario
Iuliu Ardelean
Iuliu Ardelean el 12 de En. de 2021
Editada: Iuliu Ardelean el 12 de En. de 2021
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.

Iniciar sesión para comentar.

Respuestas (1)

Rupesh
Rupesh el 15 de Feb. de 2024
Editada: Rupesh el 29 de Feb. de 2024
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!

Categorías

Más información sobre Geometric Transformation and Image Registration en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by