Displaying textured 3D models

I have a PLY made from a stereophotogrammatic scanner. It also has a texture file in jpg format. I tried setting the option for these texture files to “scalar overlay” and asked it to apply to the model I already loaded. When I do that, nothing happens, no error message nor the trace of the texture files as far as I can tell. There is no scalar listed under the “Scalar” tab of the models module.

This is with 4.8.1 on windows.

If you loaded the ply file as a model and the jpg texture file as a volume, then you can apply the texture to the model by using Texture model module of SlicerIGT extension.


I just installed IGT, I don’t seem to have textured mesh module as seen in video. I do have the texture model module, but it doesn’t seem to do anything when I choose the ply as the model, and the jpg as the texture and hit apply. If I check the “set color information as point data”, then I get these error messages.

Traceback (most recent call last):
File “C:/Users/Murat/AppData/Roaming/NA-MIC/Extensions-26813/SlicerIGT/lib/Slicer-4.8/qt-scripted-modules/TextureModel.py”, line 114, in onApplyButton
logic.applyTexture(self.inputModelSelector.currentNode(), self.inputTextureSelector.currentNode(), self.addColorAsPointAttributeCheckbox.checked)
File “C:/Users/Murat/AppData/Roaming/NA-MIC/Extensions-26813/SlicerIGT/lib/Slicer-4.8/qt-scripted-modules/TextureModel.py”, line 131, in applyTexture
self.convertTextureToPointAttribute(modelNode, textureImageNode)
File “C:/Users/Murat/AppData/Roaming/NA-MIC/Extensions-26813/SlicerIGT/lib/Slicer-4.8/qt-scripted-modules/TextureModel.py”, line 153, in convertTextureToPointAttribute
assert numOfPoints == tcoords.GetNumberOfTuples(), “Number of texture coordinates does not equal number of points”
AttributeError: ‘NoneType’ object has no attribute ‘GetNumberOfTuples’

Yes, the module has been renamed to Texture model, as I wrote above.

It seems that your PLY does not have texture coordinates, therefore, you cannot apply a texture. It would be nice if you could add a check there in line 153 to display a message box if tcoords is None instead of just logging the error message and send a pull request.

Have you applied any processing to the PLY file that could have removed the texture coordinates?

Sorry, I don’t normally work with this data, so I don’t know whether there has been any processing done to it. This is from 3dMD. All I can say texture is visible when I load the same file into the meshlab.

Can you share a data set?

Sure the 131015103819.jpg and 131015103819.ply in

Thank you for the sample data. It seems that VTK cannot load texture coordinates from this .ply file. The simplest workaround is to load the data set in MeshLab and save as .obj file and load the .obj file into Slicer. Texture coordinates seems to be stored in a more standardized way in .obj files and VTK can find it there. If it is important for you to load .ply files directly then it should be possible to fix it quite easily.

Does the texture need to be an overlay? If you import the file into Meshlab, you can apply the filter: Transfer texture to vertex color, then transfer the vertex color to face color and export as a new ply mesh with only face color. Then open in 3D Slicer, go to Models and check the “Scalars Visible” box, select RGB from the dropdown and it will load. I also got it to work with an obj as long as the color is “face color.” For some reason, it would not read the color correctly if it was saved in the vertex.


1 Like

How can we generate texture that is in RGB values that are next to the vertices in an OBJ file?

What I mean by that is, I have OBJ files that have RGB values for texture already in the file. How can I load this into the scene?

We don’t support textured models natively, but you can write a script to do it.


If someone does not want to copy-paste scripts then the “Texture model” module in SlicerIGT extension can be used for this:

The module even has the option of assigning texture values to each mesh point, just in case you want to perform mesh processing based on texture values or want to save the textured model into a single vtk or ply file. The texture image can contain more details than what can be reconstructed from point data, so the point-sample-based color representation is not a complete replacement of texture mapping.

I am confused with how you imported the file as a volume, unless this was already a separate file to begin with that contained only the RGB values. How do you separate the RGB values from the OBJ file?

The texture image (png file) was loaded as usual, using “Add data”.

The user experience could be improved by automatically loading associated texture files; and by saving in the scene the information that a texture is associated with a model (currently, the association between the model and texture image is not stored persistently in the scene).

Ah, so this goes back to my original question then. I do not have a PNG file for the texture, but rather I have a OBJ file with both the vertices and texture values (similar to the way you said you can save OBJ files with these), and faces.

An OBJ file cannot store per-vertex color, just texture coordinates (see specification). The color is determined by mapping portions of the texture image (specified by the texture coordinates) on the rendered surface.

If you don’t have the texture image then you won’t have colors (other than the uniform colors that are defined in the material file).

There might be non-standard variations of file formats, so if you are sure that you have per-vertex color information in your OBJ files then you can upload an example somewhere and post the link here so that we can have a look.

1 Like

So, I can’t share the OBJ file itself because of HIPAA laws, but I can show you what I mean:

o Object.1
v 9.140000 73.727997 416.315002 43 21 15
v 1.630000 59.623001 408.157990 87 4 0
v -2.048000 65.589996 382.217987 88 28 4
v -2.800000 72.429001 408.101013 105 23 0
v 12.335000 73.512001 408.225006 18 0 0
v -1.555000 65.552002 382.286987 84 21 0
v -1.957000 65.717003 382.250000 76 28 15
v -1.655000 65.588997 382.240997 75 28 16
v 5.374000 74.228996 408.181000 73 0 0
v -1.758000 65.700996 382.296997 72 27 15
v -1.955000 65.455002 382.290009 90 19 0
v 9.362000 73.671997 416.255005 36 14 9
v -1.623000 65.397003 382.309998 138 10 0
v -1.926000 65.624001 382.136993 76 28 15
v -2.633000 72.100998 407.997009 65 12 5
v -1.557000 65.433998 382.281006 52 21 8
v -1.742000 65.462997 382.190002 90 30 7
v -1.749000 65.598999 382.195007 75 28 16
v -2.008000 65.794998 382.437988 77 23 7
v -1.943000 65.788002 382.437012 85 12 0
v -1.846000 65.775002 382.441986 85 12 0
v -2.010000 65.475998 382.471985 85 23 0
v 8.897000 73.684998 416.281006 50 19 6
v 9.296000 73.656998 416.371002 36 14 9
v -0.800000 58.567001 408.160004 47 29 0
v 15.982000 66.615997 408.125000 45 1 0
v -2.085000 65.720001 382.446014 77 23 7
v -1.710000 65.752998 382.471008 82 14 0
v 4.327000 58.469002 408.197998 73 25 0
v -1.419000 65.384003 382.468994 52 21 8
v 7.911000 60.262001 408.196991 42 0 0
v 6.899000 59.730000 408.048004 1 0 0
v 6.653000 59.680000 408.141998 18 0 0
v -4.153000 56.791000 408.169006 43 0 0
v -1.371000 65.426003 382.481995 53 25 16
v 14.071000 60.319000 408.161987 62 8 0
v -1.426000 65.517998 382.416992 74 22 0
v 9.142000 73.612000 416.453003 53 21 0
v -1.588000 65.345001 382.425995 138 10 0
v -1.496000 65.623001 382.450012 74 22 0

Thanks, this snippet was useful. While vertex color cannot be stored in standard OBJ files, it seems that there is a workaround that is used in your file, too. VTK does not support this workaround, but probably you can find other software that does.

Therefore, I would recommend load the non-standard OBJ file using a software that supports per-vertex colors (you can try MeshLab) then save it into a standard PLY file (that supports per-vertex coloring). If you save the vertex colors in uchar type properties with the names red, green, and blue then Slicer will load the vertex colors.

ok thank you. Is there any chance that this might be something done in the future? I am collaborating with some people who would very much appreciate it, but I don’t want to get their hopes up.