File Exchange

image thumbnail

Texture Patch

version 1.0.0.0 (183 KB) by Dirk-Jan Kroon
Show a 3D triangulated mesh ( patch ) with a texture

10 Downloads

Updated 02 Jul 2010

View License

This function PATCHT, will show a triangulated mesh like Matlab function Patch but then with a texture.

patcht(FF,VV,TF,VT,I,Options);

inputs,
FF : Face list 3 x N with vertex indices
VV : Vertices 3 x M
TF : Texture list 3 x N with texture vertex indices
VT : Texture Coordinates s 2 x K, range must be [0..1] or real pixel postions
I : The texture-image RGB [O x P x 3] or Grayscale [O x P]
Options : Structure with options for the textured patch such as
EdgeColor, EdgeAlpha see help "Surface Properties :: Functions"

Options.PSize : Special option, defines the image texturesize for each
individual polygon, a low number gives a more block
like texture, defaults to 64;

note:
On a normal PC displaying 10,000 faces will take about 6 sec.

Example,

% Load Data;
load testdata;
% Show the textured patch
figure, patcht(FF,VV,TF,VT,I);
% Allow Camera Control (with left, right and center mouse button)
mouse3d

Comments and Ratings (25)

Omar Fakhr

Hi, I only get an empty figure. Can you please help

how do i get TF and VT parameters from a .jpg image?
thanks

Udaib khan

hi i have two images suppose one is logo image and other is shirt image now i want to apply logo image as a texture to some xy coordinate of shirt image so how to do it please guide

is it possible to load multiple images for the texture?

hieu vu

https://www.mathworks.com/matlabcentral/profile/authors/1058872-andrea-tagliasacchi, you have a small problem in here. In Matlab, only surface has property "texturemap". You can not apply 'texturemap' in the patch object directly. The Author has generated the useful code. Thank him so much!

I think this code is now obsolete.
Look at "Example — Texture Mapping a Surface" in the matlab documentation.

Kyle

Works well. I slightly changed the conversion from texture coordinates to image coordinates to work for my textures.

Previous
67 VT2(:,1)=(size(I,1)-1)*(VT(:,1))+1;
68 VT2(:,2)=(size(I,2)-1)*(VT(:,2))+1;

New Lines
67 VT2(:,1) = (1-VT(:,2))*size(I,1);
68 VT2(:,2) = VT(:,1)*size(I,2);

Ghazal

how to get these parameters TF and VT

arun singh

how can we use this function to map texture on a 3D model from a 2D face image.(Point to Point texture map. Only face texture and leave everything else in the 2D image.) .... ?

StellaG

@tn_with_8fusa: Thank you very much! To enable the code on "any" Matlab Version, I made the following adaptation:

x1=sizep; y1=sizep; x2=sizep; y2=0; x3=0 ;y3=0; % original
version_str = version;
index_year = regexp(version_str,'(R');
if str2double(version_str(index_year+2:end-2))>2013
y3=sizep; %new
end

StellaG

very good work! Thank you!

In 2014b, there is a problem showing texture.

When 127 line of patcht.m is corrected as follows, this problem is settled.

x1=sizep; y1=sizep; x2=sizep; y2=0; x3=0 ;y3=sizep;

Amir

I would like to know how you calculated VT and why the number of VT is different from VV.

Best
Noureddine

Amir

I did not understand something else in your example is VT why the number of vertices is larger than vv.

Amir

is that this function is limited by a number faces or not

Vinayak

Hi, I cannot understand the following:

1) What is the "TF" variable and how do I create it if I have vertices (VV), trinagles (FF) and texture coordinates (VT)?

2) In your "testdata", I see that the number of texture coordinates in VT are not saem is the number of vertices. However, should that not be the same or am I missing something here?

Your guidance is highly appreciated.

Best,
Vinayak

This is awesome, I have been looking for such a code for a such a long time. Congrats.

It would be appreciated to change the help with the correct matrix sizes.
A strange thing I found is that it works correctly only if I flip the x and y image coordinate in the matrix, could you check?
Finally, with gray images it show color-mapped texture. The work-around I found is to use three equal layer of gray levels like a color image.

Perfect job! Thank you! You saved a lot of my time. Just one remark: in the comments/help you wrongly specified the size of the input matrices FF, VV, TF and VT. They should be transposed.

Paulo

*Peter-bone,
You can try to change the figure “Renderer” (painters, z-buffer or OpenGL), after you displayed your textured-object.
set(gcf,'Renderer','OpenGl');

But it can also be a problem with your video-card driver.

Peter Bone

I'm using 2008b. The example did not texture map correctly. I did not get the image shown. Something is wrong.

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux