Exemplo n.º 1
0
def free():
  #Loader.releaseAllCaches()
  #System.out.println("Released all")
  #
  # Instead of releasing all, release half of all loaded images
  try:
    image_n_bytes = IMAGE_SIZE
    projects = Project.getProjects()
    if 0 == projects.size():
      return
    loader = projects[0].getLoader()
    f = Loader.getDeclaredField("mawts")
    f.setAccessible(True)
    mawts = f.get(loader)
    n_cached_images = mawts.size()
    n_bytes_released = 0
    if n_cached_images > 0:
      n_bytes_to_release = int((n_cached_images * 0.5) * image_n_bytes)
      n_bytes_released = loader.releaseMemory(n_bytes_to_release)
      if 0 == n_bytes_released:
        # There may be enough free memory so the loader refused to release anything,
        # therefore ask the cache instance itself to actually remove the amount requested
        n_bytes_released = mawts.removeAndFlushSome(n_bytes_to_release)
      System.out.println("Released " + str(n_bytes_released) + " out of " + str(n_bytes_to_release))
      loader.printCacheStatus()
    if 0 == n_bytes_released:
       # All memory retained is in the form of native arrays stored for loading images later
      CachingThread.releaseAll()
      System.out.println("Cleared CachingThread cache.")
  except:
    traceback.print_exc(file=sys.stdout)
def run():
  projects = Project.getProjects()
  if projects is None or projects.isEmpty():
    IJ.log('No project open!')
    return
  ls = projects.get(0).getRootLayerSet()
  trees = ls.getZDisplayables(Treeline)
  trees.addAll(ls.getZDisplayables(AreaTree))
  if trees.isEmpty():
    IJ.log('No trees to process!')
    return
  dc = DirectoryChooser('Target folder')
  targetFolder = dc.getDirectory()
  if targetFolder is None:
    return # user canceled
  if targetFolder[len(targetFolder) -1] != '/':
    targetFolder += '/'
  fdir = File(targetFolder)
  for f in fdir.listFiles():
    if f.isHidden():
      continue
    yn = YesNoCancelDialog(IJ.getInstance(), "WARNING", "Folder not empty! Continue?")
    if yn.yesPressed():
      break
    else:
      return
  process(trees, targetFolder)
Exemplo n.º 3
0
def initTrakem(path, nbLayers, mipmaps = False): #initialize a project
	path = cleanLinuxPath(path)
	ControlWindow.setGUIEnabled(False)
	project = Project.newFSProject("blank", None, path)
	project.getLoader().setMipMapsRegeneration(mipmaps)
	layerset = project.getRootLayerSet()
	for i in range(nbLayers): # create the layers
		layerset.getLayer(i, 1, True)
	project.getLayerTree().updateList(layerset) #update the LayerTree
	Display.updateLayerScroller(layerset) # update the display slider
	IJ.log('TrakEM project initialized with ' + str(nbLayers) + ' layers and stored in ' + path + ' (but not saved yet)')
	return project
Exemplo n.º 4
0
def run():
    global cal, pw, ph
    projects = Project.getProjects()
    if projects is None or projects.isEmpty():
        IJ.log('No project open!')
        return
    p = projects.get(0)
    ls = p.getRootLayerSet()
    cal = ls.getCalibrationCopy()
    pw = float(cal.pixelWidth)
    ph = float(cal.pixelHeight)
    rpt = p.getRootProjectThing()

    add_recursively(rpt, None)
Exemplo n.º 5
0
def main(linearAlignmentDir,ImageDir,trackEMfile,verbose=False):
  """Run the main Fiji-based functionality.
  """
  from jython_imports import AffineModel2D,InverseTransformMapping
  from ini.trakem2.display import Display, Patch
  from ini.trakem2 import Project
  
  #get a list of all pairwise files (has _to_ in midddle)

  transform_files = [f for f in os.listdir(linearAlignmentDir) if 'txt' in os.path.splitext(f)[1]]
  transform_files.sort()
  
  dirname=os.path.split(os.path.split(ImageDir)[0])[1]
  
  target = Project.newFSProject(dirname, None, ImageDir,True)
Exemplo n.º 6
0
def run():
  global cal, pw, ph
  projects = Project.getProjects()
  if projects is None or projects.isEmpty():
    IJ.log('No project open!')
    return
  p = projects.get(0)
  ls = p.getRootLayerSet()
  cal = ls.getCalibrationCopy()
  pw = float(cal.pixelWidth)
  ph = float(cal.pixelHeight)
  rpt = p.getRootProjectThing()

  add_recursively(rpt,None)

  add_connectors_recursively(rpt)
Exemplo n.º 7
0
def readWriteXMLTransform(projectPath,layerIndex,folder):
	'''
	1-Take the TrakEM project 'projectPath'
	2-Read the transformation of the first patch of layer 'layerIndex'
	3-Read the locations of the first patch of layer 'layerIndex' and layer '1-layerIndex'. This is used to calculate the offset of the EM and LM images in the initial transformation file
	4-Write as a simple text file in folder + title of the project + InitialTransform.txt
	'''
	project = Project.openFSProject(projectPath, False)
	layerset = project.getRootLayerSet()
	layers = layerset.getLayers()
	layer = layerset.getLayers().get(layerIndex)
	patches = layer.getDisplayables(Patch)
	t =  patches.get(0).getAffineTransform()

	transPath = folder + project.getTitle() + 'InitialTransform.txt.txt'
	f = open(transPath,'w')
	f.write( str(t.getScaleX()) + "\n")
	f.write( str(t.getShearY())+ "\n")
	f.write( str(t.getShearX())+ "\n")
	f.write( str(t.getScaleY())+ "\n")
	f.write( str(t.getTranslateX())+ "\n")
	f.write( str(t.getTranslateY())+ "\n")

	f.write ( str( layers.get(layerIndex).getDisplayables(Patch).get(0).getX() ) + '\n')
	f.write ( str( layers.get(layerIndex).getDisplayables(Patch).get(0).getY() ) + '\n')
	f.write ( str( layers.get(1-layerIndex).getDisplayables(Patch).get(0).getX() ) + '\n')
	f.write ( str( layers.get(1-layerIndex).getDisplayables(Patch).get(0).getY() ) + '\n')
	f.close()
	IJ.log('Transformation saved in: ' + transPath)
	# read the parameters of the transformations
	trans = []
	f = open(transPath,'r')
	while 1:
		line = f.readline()
		if not line: break
		IJ.log(line)
		trans.append(float(line))
	f.close
	IJ.log('Transformation: ' + str(trans))
	closeProject(project)
	return trans
Exemplo n.º 8
0
for node in tl.getRoot().getSubtreeNodes():
	if node.getParent() is not None:
		if node.getConfidence() < 5:
			p = array([node.x, node.y], 'f')
  			affine.transform(p, 0, p, 0, 1)
  			x, y = p
  			x *= cal.pixelWidth
  			y *= cal.pixelHeight
  			z = node.getLayer().getZ() * cal.pixelWidth

			locs.append([x, y, z])
  
print locs

proj = Project.getProjects()[0]
ls = proj.getRootLayerSet()

neuToDisp = tl

d3d = Display3D.get(ls)
exe = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors())

allOuts = []
allOuts.append(exe.submit(d3d.createMesh(proj.findProjectThing(neuToDisp), neuToDisp, 1)))

ii = 0
for iffy in locs:
	print iffy[0], iffy[1], iffy[2]
	ii += 1
	allOuts.append(exe.submit(ContentCreator(d3d, createFatPoint(iffy[0],iffy[1],iffy[2],300), Color3f(Color.red), "name" + str(ii))))
Exemplo n.º 9
0
    "/data/research/se/celegans/dataset3/N2DA_1430-2/M5/",
    "/data/research/se/celegans/dataset3/N2DA_1430-2/N1/",
    "/data/research/se/celegans/dataset3/N2DA_1430-2/N2/"
]

for i in range(len(proj_list)):

    data_dir = proj_list[i]
    proj_dir = os.path.join(data_dir, "montage_v1")
    img_dir = os.path.join(data_dir, "clahe_new")

    if not os.path.isdir(proj_dir):
        os.makedirs(proj_dir)

    ## Create new project
    project = Project.newFSProject("blank", None, proj_dir)
    layerset = project.getRootLayerSet()

    ## Import tiles
    # Get all layers
    f = open(os.path.join(data_dir, "tile_location.txt"), "r")

    z_list = []
    for l in f.readlines():

        elem = l[:-1].split(" ")
        fname = elem[0]
        xloc = int(elem[1])
        yloc = int(elem[2])
        zloc = int(elem[3])
        z_list.append(zloc)
Exemplo n.º 10
0
from ini.trakem2.imaging.filters import CLAHE
from mpicbg.trakem2.align import AlignmentUtils
import os
import re
import math
import csv
from java.awt.geom import AffineTransform
 

wafer = "S2-W003-W008"
# bucket = "/usr/people/tmacrina/seungmount/research/"
bucket = "/mnt/data0/"
# writefile = bucket + "tommy/150528_zfish/" + wafer + "_import.txt"
project_folder = bucket + "tommy/150502_piriform/S2-W001/"

project = Project.getProject("150605_S2-W001_elastic_S2-W002_affine.xml")
loader = project.getLoader()
# loader.setMipMapsRegeneration(False) # disable mipmaps
layerset = project.getRootLayerSet()



layers = layerset.getLayers()
starting_index = len(layers) + 1

task = loader.importImages(
          layerset.getLayers().get(0),  # the first layer
          project_folder + wafer + "_import.txt", # the absolute file path to the text file with absolute image file paths
          "\t", # the column separator  <path> <x> <y> <section index>
          1.0, # section thickness, defaults to 1
          1.0, # calibration, defaults to 1
# To create envelopes for all lineages, do:
#   regex = None
# ... and then don't show the plots (all will be together):
#   show_3D = False

# ASSUMES pipes have the same exact name across all TrakEM2 projects.
# The 'name' is the title of the pipe node in the Project Tree
# and any of its parent nodes, chained. So if you want all DPM lineages
# and these are grouped in a DPM lineage group, then use "DPM".


from ini.trakem2 import Project
from java.awt import Color
from java.io import File

projects = [p for p in Project.getProjects()]
# Add more colors if you have more than 6 projects open
colors = [Color.white, Color.yellow, Color.magenta, Color.green, Color.blue, Color.orange]
sources_color_table = {}
for project, color in zip(projects, colors):
  sources_color_table[project] = color


# 1. The project to use as reference--others are compared to it.
reference_project = projects[0]
# 2. The regular expression to match. Only pipes whose name matches it
# will be analyzed. If null, all are matched.
regex = None    # For a single one, put its name:  "DPMm2"
# 3. A list of text strings containing regular expressions.
# Any pipe whose name matches any will be ignored.
ignore = ["unknown.*", "poorly.*", "MB.*", "peduncle.*", "TR.*"]
from ini.trakem2 import Project
from ini.trakem2.display import Display

projects = Project.getProjects()

original = projects[0]
new_project = projects[1]

patches = None
layer2 = None

for display in Display.getDisplays():
  if display.getProject() == original:
    patches = display.getSelection().getSelected()
  elif display.getProject() == new_project:
    layer2 = display.getLayer()


for patch in patches:
  layer2.add(patch.clone(new_project, True))
Exemplo n.º 13
0
def openTrakemProject(path, mipmap = False):
	project = Project.openFSProject(cleanLinuxPath(path), False)
	return getProjectUtils(project, mipmap)
Exemplo n.º 14
0
from java.lang.reflect import Field
from java.lang import Runtime
from ini.trakem2.persistence import FSLoader
from ini.trakem2 import Project

loader = Project.getProjects()[0].getLoader()

f = FSLoader.getDeclaredField("regenerator")
f.setAccessible(True)
f.get(loader).shutdownNow()

loader.restartMipMapThreads(Runtime.getRuntime().availableProcessors())

f = FSLoader.getDeclaredField("regenerating_mipmaps")
f.setAccessible(True)
f.get(loader).clear()

f = FSLoader.getDeclaredField("n_regenerating")
f.setAccessible(True)
f.get(loader).set(0)

  
Exemplo n.º 15
0
# Adapted from: 
# http://fiji.sc/TrakEM2_Scripting#Concatenating_multiple_project_XML_files_by_copying_all_their_layers

from ini.trakem2 import Project
from ini.trakem2.display import Patch
from ini.trakem2.utils import Utils

# Wafer
bucket = '/mnt/bucket/labs/seung/research/'
# project_folder = bucket + 'tommy/150528_zfish/'
# project_folder = bucket + 'tommy/150502_piriform/'
project_folder = bucket + 'tommy/trakem_test/150622_fix_rigid'

# Get the first open project
project = Project.getProject('turtle_rigid.xml')

# Get layerset
layerset = project.getRootLayerSet()

start = 0
finish = 2

layers = layerset.getLayers()[start:finish]

# Regenerate all image mipmaps
futures = []
for layer in layers:
	for patch in layer.getDisplayables(Patch):
		futures.append(patch.updateMipMaps())
Utils.wait(futures)
Exemplo n.º 16
0
from ij import IJ
from ini.trakem2.imaging.filters import CLAHE
from mpicbg.trakem2.align import AlignmentUtils
import os
import re
import math
import csv
from java.awt.geom import AffineTransform
 

wafer = "W004"
bucket = "/usr/people/tmacrina/seungmount/research/"
project_folder = bucket + "tommy/150528_zfish/"
# project_folder = "/mnt/data0/tommy/tests/150501_trakem_project_creation/"

project = Project.newFSProject("blank", None, project_folder)
loader = project.getLoader()
# loader.setMipMapsRegeneration(False) # disable mipmaps
layerset = project.getRootLayerSet()
# layerset.setSnapshotsMode(1) # outlines

task = loader.importImages(
          layerset.getLayers().get(0),  # the first layer
          project_folder + wafer + "_import.txt", # the absolute file path to the text file with absolute image file paths
          "\t", # the column separator  <path> <x> <y> <section index>
          1.0, # section thickness, defaults to 1
          1.0, # calibration, defaults to 1
          False, # whether to homogenize contrast, avoid
          1.0, # scaling factor, default to 1
          0) # border width
 
def exportWavefront(zds, filepath):
    """
  Takes a sequence of ZDisplayable instances and saves all as meshes to disk in wavefront format.
  A materials .mtl file is saved along with it.
  See: https://github.com/fiji/3D_Viewer/blob/master/src/main/java/customnode/WavefrontExporter.java
  """
    meshes = {
        zd.getTitle(): d3d.createMesh(zd.project.findProjectThing(zd), zd,
                                      resampling_factor).call()
        for zd in zds
    }
    WavefrontExporter.save(meshes, filepath)


project = Project.getProjects()[0]
d3d = Display3D.getDisplay(project.getRootLayerSet())


def exportSelectedAsWavefront(project, filepath):
    """ Select a node in the Project Tree, then run this function
      to export the meshes of all ZDisplayable under the node
      in Wavefront format. """
    exportWavefront(list(loadFromSelectedTreeNode(project)), filepath)


# Strategy 1: provide a list of IDs
# The IDs of the AreaList (zDisplayables: arealists, balls etc.) instances
"""
to_add = [67163, 66596]
Exemplo n.º 18
0
    os.mkdir(out_folder + "/storm_merged/")

##determine image canvas size (query each image)

imp = IJ.openImage((imlist[0]))
#print imp.width

im_width = imp.width
print im_width

im_height = imp.height
print im_height

ControlWindow.setGUIEnabled(False)
# 1. Create a TrakEM2 project
project = Project.newFSProject("blank", None, out_folder)
loader = project.getLoader()
loader.setMipMapsRegeneration(True)  # disable mipmaps
layerset = project.getRootLayerSet()

#  2. Create 10 layers (or as many as you need)
for i in range(num_sections):
    layerset.getLayer(i, 1, True)
    layerset.setDimensions(im_width, im_height, LayerSet.NORTHWEST)
# ... and update the LayerTree:
project.getLayerTree().updateList(layerset)
# ... and the display slider
Display.updateLayerScroller(layerset)
filenames = sorted(os.listdir(storm_merged_folder))
filenames1 = sorted(os.listdir(conv_561_folder))
filenames2 = sorted(os.listdir(conv_merged_folder))
from java.util.concurrent import Executors, TimeUnit

SPRING_LENGTH = 100
spring_triangle_height_twice = 2 * Math.sqrt(0.75*SPRING_LENGTH*SPRING_LENGTH)
LAYER_SCALE = 1.0
STIFFNESS = 0.1
MAX_STRETCH = 2000.0
DAMP = 0.9
MAX_ITERATIONS = 5000 #1000
MAX_PLATEAU_WIDTH = 200
MAX_EPSILON = 6
MIN_NUM_MATCHES = 1 # minimum for TranslationModel2D()
MAX_NUM_THREADS = 40

# project = Project.getProject('stack_import.xml')
project = Project.getProject('montage_align.xml')

bucket = "/usr/people/tmacrina/seungmount/research/"
# project_folder = bucket + "tommy/150502_piriform/"
project_folder = bucket + "tommy/trakem_tests/150709_elastic_montage/"
input_folder = project_folder + "affine_block_matching/points/"
# input_folder = project_folder + "affine_block_matching/layers/"

all_files = os.listdir(input_folder)

def get_tiles(layer):
	po = ParamOptimize()
	po.maxEpsilon = 25.0
	po.minInlierRatio = 0.0
	po.minNumInliers = 12
	po.expectedModelIndex = 1
Exemplo n.º 20
0
            # print 'found', connector
            if connector.intersectsOrigin(area, la):
                if nd in outgoing:
                    outgoing[nd].append(connector)
                else:
                    outgoing[nd] = [connector]
            else:
                if nd in incoming:
                    incoming[nd].append(connector)
                else:
                    incoming[nd] = [connector]
    return {'outgoing':outgoing, 'incoming':incoming}


# get the first open project
project = Project.getProjects().get(0)
projectRoot = project.getRootProjectThing()

neurites = projectRoot.findChildrenOfTypeR("neurite")
for neurite in neurites:
    areatrees = neurite.findChildrenOfTypeR("areatree")
    for areatree in areatrees:
        areatree = areatree.getObject()
        root = areatree.getRoot()
        if root is None:
            continue

        layerset = areatree.getLayerSet()
        calibration = layerset.getCalibration()
        affine = areatree.getAffineTransform()
        # outAndInArray = areatree.findConnectors()
Exemplo n.º 21
0
    "/data/research/se/celegans/dataset3/N2DA_1430-2/M5/",
    "/data/research/se/celegans/dataset3/N2DA_1430-2/N1/",
    "/data/research/se/celegans/dataset3/N2DA_1430-2/N2/"
]

for i in range(len(proj_list)):

    data_dir = proj_list[i]
    proj_dir = os.path.join(data_dir, "montage_v1")
    img_dir = os.path.join(data_dir, "transformed")

    if not os.path.isdir(img_dir):
        os.makedirs(img_dir)

    proj_name = os.path.join(proj_dir, "montage_v1.xml")
    project = Project.openFSProject(proj_name)
    layerset = project.getRootLayerSet()

    layer_list = layerset.getLayers()

    fname_trans = os.path.join(data_dir, "transform.csv")
    fw = open(fname_trans, "w")
    for j in range(len(layer_list)):

        layer = layer_list[j]
        tiles = layer.getDisplayables(Patch)

        patches = layer.getDisplayables(Patch)

        for k in range(len(patches)):