warping error - array is wrong size or shape
조회 수: 11 (최근 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
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
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 . ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1618173/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1618173/image.jpeg)
You can refer to following documents for more information regarding Image Wrap Operations for better understanding.
Hope this helps!
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!