matlab - How to plot a surface with a texture map -


i want plot surface texture map on it, conditions not "ideal" ones.

first lets explain have.

i have set of points (~7000) image coordinates, in grid. this points not define perfect squares. it not meshgrid. sake of question, lets assume have 9 points. lets ilustrate have image:

 x=[310,270,330,430,410,400,480,500,520]  y=[300,400,500,300,400,500,300,400,500] 

enter image description here lets can "structure" of grid,

 size1=3;  size2=3;  points=zeros(size1,size2,2)  x=[310,270,330;     430,410,400;     480,500,520]  y=[300,400,500;     300,400,500;     300,400,500]  points(:,:,1)=x;  points(:,:,2)=y; 

and lets have 3rd dimension, z.

edit: forgot add piece if info. triangulate points in image , 3d correspondence, when displayed in surface don't have x , y coords of image, simplification of given data lets x=x/2 y=y/3

and have:

 points=zeros(size1,size2,3)  z=[300,330,340;     300,310,330;     290,300,300]   surf(points(:,:,1)/2,points(:,:,2)/3,points(:,:,3)) 

enter image description here

what want plot surface in 3d image texture. each element should have texture piece have in first image.

this needs work huge datasheets. don't specially need fast.

related post (but has meshgrid initial set of points) : texture map 2d grid

pd: can post original images + real data if needed, posted because think easier small data.

i don't think can want matlab's built in commands , features. using technique my other answer high-res version of grid can you.

by "high-res", mean interpolated version of non-uniform grid denser data points. used sample texture @ denser data points can drawn using texturemap feature of surf. can't use normal 2d interpolation, however, because need preserve non-uniform grid shape. came with:

function g = nonuniformgridinterp2(g, sx, sy)  [a,b] = size(g); g = interp1(linspace(0,1,a), g, linspace(0,1,sy)); % interp columns g = interp1(linspace(0,1,b), g', linspace(0,1,sx))'; % interp rows 

note have call twice interpolate x , y points independently. here's example of original grid , interpolated version 10 points in each direction.

plot of original , interpolated grids

here's how use high-res grid interp2 , texturemap.

function nonuniformtexturemap  % define non-uniform surface grid x = [310,270,330; 430,410,400; 480,500,520]; y = [300,400,500; 300,400,500; 300,400,500]; z = [300,330,340; 300,310,330; 290,300,300];  % texture data load penny % loads data in variable p  % define texture grid based on image size % note: using 250-550 a,b covers range used x,y [m,n] = size(p); [a,b] = meshgrid(linspace(250,550,n), linspace(250,550,m));  % high-res version of non-uniform grid s = 200; % number of samples in each direction x2 = nonuniformgridinterp2(x, s, s); y2 = nonuniformgridinterp2(y, s, s);  % sample (map) texture on non-uniform grid c = interp2(a, b, p, x2, y2);  % plot original , high-res grid figure plot(x(:),y(:),'o',x2(:),y2(:),'.') legend('original','high-res')  % plot surface using sampled points color figure surf(x, y, z, c, 'edgecolor', 'none', 'facecolor','texturemap') colormap gray 

plot of mapped texture


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -