Import Labels as Arealist according to layer ID and not Z value

Dear list,
I’m trying to import a segmented stack as area list in TrakEM2 using the “Import labels as arealists” function. This option works well if the z-values are not calibrated, otherwise new layers 1 pixel spaced are created to accomodate the segmented slices of the stack.
As the layers are not equally spaced I cannot easily reset and re-set the z values of the layers.

I also tried the script " Adding areas to an AreaList by scanning pixel values in the slices of a stack"
but I run into an error:

ali.addArea(layer.getId(), m.values().iterator().next())
AttributeError: ‘list’ object has no attribute ‘iterator’

Can anyone help me with a script to import, or to re-set the z-values of each layer after resetting and importing the labels?

Thank you very much

Federico

@albertcardona

Playing with the TrakEM2 scripting examples written by Albert Cardona I’ve found a solution, not elegant, a bit tricky… but working.

Hope this could be useful for somebody else! Still, solving the error in the “Adding areas to an AreaList by scanning pixel values in the slices of a stack” script example could be very useful for the minimal coders like me!

Here my solution to the problem

  1. Run script n°1 to produce a text file with a list of the z values of all the layers in the Project
    (3963.8701,4360.2571,4756.6441,5153.0312,5549.4182,5945.8052…)
from ini.trakem2.display import Display, Patch
from ini.trakem2 import Project
from ij.text import TextWindow

ProjName= Project.getProjects()

#create an empty list that will be filled with the layer's z values
zList=[ ]

for layer in Display.getFront().getLayerSet().getLayers():
							print layer
							z = layer.getZ()
							zList.append(str(z))

csv = ",".join(zList)
 
t = TextWindow(str(ProjName)+"zList", csv, 400, 400)
  1. Reset the z-layer and thicknes ( by right clicking at the top of the layer list)
  2. Import the stack from the display right click option (import labels as arealists)
  3. Run a second script to re-assign to each layer its calibrated value, just copy from the zList text file all the values (right click and copy the values and than paste them in the script)
from ini.trakem2.display import Display, Patch
from ini.trakem2 import Project
from ij.text import TextWindow

#paste the z-values from the zList Text files inside the [ ]
zList = []

# Obtain the LayerSet instance:
layerset = Display.getFront().getLayerSet()

layers=layerset.getLayers()
for z,layer in zip(zList,layers):
  		layer.setZ(z)

# Update the GUI
layerset.getProject().getLayerTree().updateUILater()

That’s it!

Federico