def run():
  if 0 == Display.getSelected().size():
    print "Nothing selected!"
    return
  tree = Display.getSelected()[0]
  if not isinstance(tree, AreaTree):
    print "Not an AreaTree!"
    return
  cal = tree.getLayerSet().getCalibration()
  for nd in tree.getRoot().getSubtreeNodes():
    area = nd.getData()
    if area is None:
      continue
    pols = M.getPolygons(area)
    if len(pols) > 1:
      report(nd, pols, tree.getAffineTransform(), cal)
      if remove_all_but_largest:
        removeAllButLargest(area, pols)
    elif len(pols) == 1:
      print "Found a single polygon with bounds: "+str(pols[0].getBounds())
  Display.repaint()
Esempio n. 2
0
def importMask(evt=None):
  display = Display.getFront()
  # Obtain an image stack
  #imp = IJ.getImage()
  imp = WindowManager.getImage("Labels")

  layerset = display.getLayerSet()
  p = layerset.getProject()

  ali = AreaList(p, "", 0, 0)
  layerset.add(ali)
  p.getProjectTree().insertSegmentations([ali])

  # Obtain the image stack
  stack = imp.getImageStack()
  # Iterate every slice of the stack
  for i in range(1, imp.getNSlices() + 1):
    ip = stack.getProcessor(i) # 1-based
    # Extract all areas (except background) into a map of value vs. java.awt.geom.Area
    m = AreaUtils.extractAreas(ip)
    # Report progress
    if len(m) > 0:
      IJ.log(str(i) + ":" + str(len(m)))
    # Get the Layer instance at the corresponding index
    layer = layerset.getLayers().get(i-1) # 0-based
    # Add the first Area instance to the AreaList at the proper Layer
    if ( m.values().iterator().hasNext() ):
      ali.addArea(layer.getId(), m.values().iterator().next())

  # Change the color of the AreaList
  ali.setColor(Color.red)
  ali.adjustProperties()
  # Ensure bounds are as constrained as possible
  ali.calculateBoundingBox(None)
  # Repaint
  Display.repaint()
# Translate any selected Displayable objects

dx = -90
dy = 129

from ini.trakem2.display import Display

# For any selected objected
for displ in Display.getFront().getSelected():
    displ.getAffineTransform().translate(dx, dy)

Display.repaint()
	print patch.getTitle()
	if cp.containsKey(patch.getTitle()):
		patch_title = patch.getTitle()[:-4]
		print patch.getId(), patch_title
		print patch.hasCoordinateTransform()

		target_patch = cp.get(patch.getTitle())
		target_patch.setCoordinateTransform(patch.getCoordinateTransform())
		target_patch.getAffineTransform().setTransform(patch.getAffineTransform())
		target_patch.updateInDatabase("transform")
		target_patch.updateBucket()

		# tform_file = folder + patch_title + '_original.xml'
		# tform_xml = open(tform_file, 'w')
		# tform_xml.write(patch.getCoordinateTransform().toXML('\t'))
	 	# tform_xml.close()

		# tform_file = folder + patch_title + '_target.xml'
		# tform_xml = open(tform_file, 'w')
		# tform_xml.write(target_patch.getCoordinateTransform().toXML('\t'))
	 	# tform_xml.close()

		print patch.getAffineTransform()
		print target_patch.getAffineTransform()

		target_layer.moveBottom(target_patch)	 				

	IJ.showProgress(i, original_patches.size())

Display.repaint()