Hi, I would like to 3D render a segmentation (model) and instead of using simple colours I would like to define a custom texture. How can I apply a custom texture that I have stored on my computer in .jpg/ .png/.exr format?
Thanks!!
There is a module in SlicerMorph that allows you load OBJ files with texture. Try and see if works for you. You may have to modify the code to make it work with your custom texture,
You can also use the TextureModel from IGT Extension. Load the 3D model, load the texture file (as a volume), and use the textureModel to apply the texture to the 3d model in the scene.
I have tried it with the texture module. My texture file is in .jpg format and I have imported it as a volume. Unfortunately it does not work that the model takes over this texture. Do you have any tips for the texture files?
Can you successfully apply that texture to the model in some other software (e.g., Meshlab)? The alternative is to apply it as vertex color (i.e., bake the texture) in other software and bring it to Slicer.
If you share your model and texture, perhaps people can give other suggestions.
You can try this in Blender. You will need to UV unwrap your model and bake the texture–even if it’s not a perfect unwrap (since CT models tend to be hi-poly) your texture might transfer well enough.
Texture mapping works nicely in Slicer. If you have any trouble then we can help but we need more information. Sharing some example files would be the easiest. You can upload them anywhere (dropbox, onedrive, etc.) and post the link here.
Thanks so much for your help, I very much appreciate it!
Here’s a link to the structure on which I would like to apply the texture (also in dropbox).
The problem was that your model did not have any texture coordinates. You can add it in any modeling software, or you can go with basic mappings in Slicer, by copy-pasting this code snippet into the Python interactor:
modelNode = getNode("structure")
textureMapper = vtk.vtkTextureMapToSphere()
textureMapper.SetInputData(modelNode.GetPolyData())
textureMapper.Update()
modelNode.SetAndObservePolyData(textureMapper.GetOutput())
The texture preview image you have uploaded (Metal041A.png) looks nice but not square shaped, so you will have some transparent regions in the textured model. If you use the color, etc. image (Metal041A_1K-JPG_Color.jpg) component then it will not look very nice. Maybe the best is to crop the preview image to square shape.
If you just want to show a simple metallic surface then you don’t need to do any texture mapping, but you can simply enable PBR interpolation (physics-based rendering) in Models module and enable “Image-based lighting” in Lights module (provided by Sandbox extension).
Thanks so much, this is incredibly helpful!