Image Analysis

From TrakEM2 to Blender

A user guide to transform your 2D traced object into 3D model in Blender

This user guide is going to detail step by step how to obtain a 3D model in blender. From the very beginning when the sample is imaged to the end; the structure in Blender.

This document is separated in 2 parts: One first part dedicated to Fiji and TrakEM2 to learn how to import, align and trace a stack.

The second part is dedicated to Blender. It explains how to save a structure in TrakEM2 and then export it in Blender. It’s going to show some basics to work with these programs.

Import stack in TrackEM2

  1. Open the software FIJI (The software can be downloaded here).
  2. Import an image sequence (File>Import>Image sequence…)
  3. Select the folder where the images are situated and click on import.
  4. Tick the box ‘Convert to 8 bit Grayscale’ and  “Use virtual stack” (to save memory).
  5. Open a new TrakEM2 canvas (File>New>TrakEM2 (blank).
  6. Choose a folder where the TrakEM2 project will be saved.

    Note: Once the destination has been chosen, two windows will open, a project window showing the node structure of your reconstruction project, and a display window in which the serial images with appear, with a tool box and list on the left hand side (see image below).

  7. Right-click in the black canvas and select Import>Stack and pick the opened stack.
  8. Set the slice thickness in pixel. To do that, the slice thickness must be divided by the pixel size (resolution). Introduce the result under slice thickness.

    Note: 10nm slice thickness / 5 nm per pixel = 2 (that means TrakEM2 has to put 2 pixels between each slice to reach the 10nm). To set the slice thickness later: Select all the images of the stack in the TrakEM2 window, under “Layers” column. Right click and select “Scale Z and thickness”. To reset the slice thickness; right-click on the image forder and select “Reset layer Z and thickness”.

  9. Set the pixel size to have a correct slice thickness (Image>Properties…) 

    Note: Set your pixel size in micron! Blender will only take the value and not the unit.

  10. Align a stack (right-click in the canvas>align).
  11. Select a type of alignment depending on what is needed.

    Note: See TrakEM2 user manual to know which type of alignment is suited.

  12. Create an area_list to trace your object. 

    Note: In the node window, add a new “area_list” to “anything” under “Template” column. Drag “anything” and “area_list” into the project folder under Project Objects column. To create a second object, simply drag the “area_list” from “Template” column to the folder suited under “Project Objects”.

  13. Trace a structure (select “Z space” in the TrakEM2 canvas and use the brush).
  14. Create a 3D model of a structure (Select an area_list>right click>Show in 3D>Choose a value between 1 and 100).
  15. Save the 3D model generated (File>Export surfaces>WaveFront).

    Note: This way only work with Java 6. A version of Fiji coupled with Java 6 is available on Fiji website for Windows and Linux users.

  16. From a version of Macintosh or Windows using Java 8, run this modified script to perform this task (Select an area_list>File>New>Script).
  17. Copy – paste the script, select Python as language and click run.
  18. The original script can be found here.
  19. Open Blender and import the .obj file under the Wavefront option (File>Import>Wavefront).
  20. To install Neuromorph or add-ons (Edit>Preferences>Add-ons>Install…).

    Note: To install Add-ons manually, pick .py files. They will be visible under “User” in the “Category” scrolling menu (by default “All” is selected).

The original script can be found here.

Thereafter, a modified script that allows the rendering of one or multiple selected area_list at the same time.

#Script to have several objects in once

from ini.trakem2.display import Display
from org.scijava.vecmath import Color3f
from customnode import WavefrontExporter, CustomTriangleMesh
from import StringWriter
from ij.text import TextWindow

# in range() enter the number of area list you want (it starts to count from the top, 0 is the first one)
for i in range(len(Display.getSelected())):
	arealist = Display.getSelected()[i]
	# Create the triangle mesh with resample of 1 (no resampling)
	# CAUTION: may take a long time. Try first with a resampling of at least 10.
	resample = 1
	triangles = arealist.generateTriangles(1, resample)
	# Prepare a 3D Viewer object to provide interpretation
	color = Color3f(1.0, 1.0, 0.0)
	transparency = 0.0
	mesh = CustomTriangleMesh(triangles, color, transparency)
	# Save the mesh as Wavefront
	name = "arealist-" + str(arealist)
	m = {name : mesh}
	meshData = StringWriter()
	materialData = StringWriter()
	materialFileName = name + ".mtl"
	objFileName = name + ".obj", materialFileName, meshData, materialData)

	# Define location of files
	filepath = "/home/anne/Desktop/"  # <-- change this for your computer!

	# Save .obj file
	full_objfilename = filepath + objFileName
	objfile = open(full_objfilename, "w")

	# Save .mtl file
	full_mtlfilename = filepath + materialFileName
	mtlfile = open(full_mtlfilename, "w")