0

I have a Mesh (Vertices and Faces). I want to project an RGB (or greyscale) Image on the mesh surface. Something like the first example in the this page.

However, the previouse example based on XYZ surface not a Mesh. Is there an altenritive for Meshs?

Humam Helfawi
  • 19,566
  • 15
  • 85
  • 160
  • `mesh` or `surf` are the same thing in terms of coordinates, they only differ by their visualisation options (`mesh` shows you the _wireframe_ surface while `surf` have more options to represent and color the surface). Get the `XData\YData\ZData` of your mesh and you can use them as coordinates for a surface. – Hoki Mar 04 '19 at 10:05
  • Thank you! XData\YData\ZData are not availble in my case. I have vertices and faces. vertices consist of X,Y,Z but if I used those values directly, it won' work. I will get this error: Error in value of property ZData Array is wrong shape or size – Humam Helfawi Mar 04 '19 at 11:18
  • Possible duplicate of [Texture mapping in MATLAB](https://stackoverflow.com/questions/2488086/texture-mapping-in-matlab) – Will Mar 04 '19 at 11:38

1 Answers1

0
I = rgb2gray(imread('peppers.png')) ;
% If structured grid 
[ny,nx] = size(I) ;
[X,Y] = meshgrid(1:nx,1:ny) ;

figure
ax = gca;
surf(X,Y,I)
shading interp 
colormap(gray)
view(2)
set(gca,'Ydir','reverse')


%% If unstructured grid 
dt = delaunayTriangulation(X(:),Y(:)) ;
p = dt.ConnectivityList ;
t = dt.Points ;
figure
ax = gca;
patch('faces',p,'vertices',t(:,1:2),'facevertexcdata',I(:),'facecolor','interp','edgecolor','none') ;
shading interp 
colormap(gray)
view(2)
set(gca,'Ydir','reverse')
Siva Srinivas Kolukula
  • 1,251
  • 1
  • 7
  • 14
  • Thanks for your reply! However, I have already Mesh and Image. I do not want to get mesh from image. I want to project image on already exist mesh – Humam Helfawi Mar 04 '19 at 11:19