Пример #1
0
from ini.trakem2.utils import Utils
from ini.trakem2.display import Display, Patch
from mpicbg.trakem2.align import Align, AlignTask

import fijiCommon as fc

namePlugin = 'init_EM'
MagCFolder = fc.startPlugin(namePlugin)
ControlWindow.setGUIEnabled(False)

EMDataFolder = os.path.join(MagCFolder, 'EMData')
MagCEMFolder = fc.makeNeighborFolder(EMDataFolder, 'MagC_EM')

imageFolders = [
    os.path.join(EMDataFolder, sectionFolderName)
    for sectionFolderName in fc.naturalSort(os.walk(EMDataFolder).next()[1])
]

nSections = len(imageFolders)
IJ.log('There are ' + str(nSections) + ' EM layers')

# reading EM metadata
EMMetadataPath = os.path.join(MagCEMFolder, 'EM_Metadata.txt')
try:  # old Atlas format
    mosaicMetadata = os.path.join(
        imageFolders[0],
        filter(lambda x: 'Mosaic' in x, os.listdir(imageFolders[0]))[0])
    root = ET.parse(mosaicMetadata).getroot()

    pixelSize = float(root.find('PixelSize').text)
    tileinfo = root.find('TileInfo')
exportedEMFolder = fc.findFoldersFromTags(
    MagCFolder, ['export_alignedEMForRegistration'])[0]
exportedLMFolder = fc.findFoldersFromTags(
    MagCFolder, ['exported_downscaled_1_' + channels[-1]
                 ])[0]  # finds the brightfield contrasted channel
temporaryFolder = fc.mkdir_p(
    os.path.join(os.path.dirname(projectPath),
                 'temporary_LMEMRegistration'))  # to save contrasted images
registrationFolder = fc.mkdir_p(
    os.path.join(os.path.dirname(projectPath),
                 'LMEMRegistration'))  # to save contrasted images

imPaths = {}
imPaths['EM'] = [
    os.path.join(exportedEMFolder, imageName)
    for i, imageName in enumerate(fc.naturalSort(os.listdir(exportedEMFolder)))
    if os.path.splitext(imageName)[1] == '.tif'
]

if BIB:
    imPaths['EM'] = [imPaths['EM'][o] for o in ordered_surface_ids]
# surfaceIds = [0,16,32,48,65,81,97,113,129,145,162,179,195,211,227,243,260,276,293,310] # optimal 16-17
# imPaths['EM'] = [imPaths['EM'][i] for i in surfaceIds]

imPaths['LM'] = [
    os.path.join(exportedLMFolder, imageName)
    for imageName in fc.naturalSort(os.listdir(exportedLMFolder))
    if os.path.splitext(imageName)[1] == '.tif'
]

# get the dimensions of the EM layerset by looking at the dimensions of the first EM image, save for next script
Пример #3
0
exportedEMFolder = fc.findFoldersFromTags(
    MagCFolder, ['export_alignedEMForRegistration'])[0]
exportedLMFolder = fc.findFoldersFromTags(
    MagCFolder, ['exported_downscaled_1_' + channels[-1]
                 ])[0]  # finds the brightfield contrasted channel
temporaryFolder = fc.mkdir_p(
    os.path.join(os.path.dirname(projectPath),
                 'temporary_LMEMRegistration'))  # to save contrasted images
registrationFolder = fc.mkdir_p(
    os.path.join(os.path.dirname(projectPath),
                 'LMEMRegistration'))  # to save contrasted images

imPaths = {}
imPaths['EM'] = [
    os.path.join(exportedEMFolder, imageName)
    for imageName in fc.naturalSort(os.listdir(exportedEMFolder))
    if os.path.splitext(imageName)[1] == '.tif'
]
imPaths['LM'] = [
    os.path.join(exportedLMFolder, imageName)
    for imageName in fc.naturalSort(os.listdir(exportedLMFolder))
    if os.path.splitext(imageName)[1] == '.tif'
]

# surfaceIds = [0,16,32,48,65,81,97,113,129,145,162,179,195,211,227,243,260,276,293,310] # optimal 16-17
# imPaths['EM'] = [imPaths['EM'][i] for i in surfaceIds]

# get the dimensions of the EM layerset by looking at the dimensions of the first EM image, save for next script
imEM0 = IJ.openImage(imPaths['EM'][0])
widthEM = imEM0.width
heightEM = imEM0.height
Пример #4
0
nbLayers = EMMetadata['nSections']
IJ.log('There are ' + str(nbLayers) + ' EM layers')

##########################################
# Stitching of the low-res EM project
##########################################
allPatchCoordinates = []

downsampledFolder = os.path.join(MagC_EM_Folder, 'MagC_EM_' + factorString)
IJ.log('downsampledFolder ' + downsampledFolder)

foldersToStitch = [
    os.path.join(downsampledFolder, folderName)
    for folderName in os.walk(downsampledFolder).next()[1]
]
foldersToStitch = fc.naturalSort(foldersToStitch)
IJ.log('foldersToStitch -------------  ' + str(foldersToStitch))

# stitching should be done in parallel but the stitching plugin does not seem to run in parallel, so fractionCores=0 -> only one core used ...
atom = AtomicInteger(0)
fc.startThreads(parallelStitch,
                fractionCores=0,
                wait=0,
                arguments=(atom, foldersToStitch, allPatchCoordinates))

#for k in range(len(foldersToStitch)):
#    sectionFolder = foldersToStitch[k]

#    tileConfigurationPath = os.path.join(sectionFolder, 'TileConfiguration_' + str(k).zfill(4) + '.registered.txt')

#    stitchCommand = 'type=[Filename defined position] order=[Defined by filename         ] grid_size_x=' + str(numTilesX) + ' grid_size_y=' + str(numTilesY) + ' tile_overlap=' + str(100 * (tileOverlapX + tileOverlapY)/2.) + ' first_file_index_x=0 first_file_index_y=0 directory=' + sectionFolder + ' file_names=Tile_{xx}-{yy}_resized_' + factorString + '.tif output_textfile_name=TileConfiguration_' + str(k).zfill(4) +'.txt fusion_method=[Do not fuse images (only write TileConfiguration)] regression_threshold=0.70 max/avg_displacement_threshold=2.50 absolute_displacement_threshold=3.50 compute_overlap subpixel_accuracy computation_parameters=[Save computation time (but use more RAM)] image_output=[Write to disk] output_directory=' + sectionFolder
Пример #5
0
from ini.trakem2 import Project, ControlWindow
from ini.trakem2.display import Patch
from java.util.concurrent.atomic import AtomicInteger

namePlugin = 'alignRigid_EM'
MagCFolder = fc.startPlugin(namePlugin)
ControlWindow.setGUIEnabled(False)
MagC_EM_Folder = os.path.join(MagCFolder, 'MagC_EM', '')
MagCParameters = fc.readMagCParameters(MagCFolder)

regModel = MagCParameters[namePlugin]['regModel']
inputFolder = fc.findFoldersFromTags(MagCFolder,
                                     ['export_stitchedEMForAlignment'])[0]
imagePaths = filter(
    lambda x: os.path.splitext(x)[1] == '.tif',
    fc.naturalSort(
        [os.path.join(inputFolder, x) for x in os.listdir(inputFolder)]))

regParams = Register_Virtual_Stack_MT.Param()
regParams.minInlierRatio = 0
regParams.registrationModelIndex = regModel  # 1-Rigid, 2-Similarity, 3-Affine
regParams.featuresModelIndex = regModel

exportForRigidAlignmentFolder = inputFolder
resultRigidAlignmentFolder = fc.mkdir_p(
    os.path.join(MagC_EM_Folder, 'resultRigidAlignment'))

################################################
# rigid alignment outside trakem2 with register virtual stack plugin because bug in trakem2
transformsPath = os.path.join(
    MagC_EM_Folder, 'rigidAlignmentTransforms_' + namePlugin + '.txt')
referenceName = fc.naturalSort(os.listdir(exportForRigidAlignmentFolder))[0]
Пример #6
0
from ini.trakem2.utils import Utils
from ini.trakem2.display import Display, Patch
from mpicbg.trakem2.align import Align, AlignTask

import sys
sys.path.append(IJ.getDirectory('plugins'))
import fijiCommon as fc 

namePlugin = 'init_EM'
MagCFolder = fc.startPlugin(namePlugin)
ControlWindow.setGUIEnabled(False)

EMDataFolder = os.path.join(MagCFolder, 'EMData')
MagCEMFolder = fc.makeNeighborFolder(EMDataFolder, 'MagC_EM')

imageFolders = [os.path.join(EMDataFolder, sectionFolderName) for sectionFolderName in fc.naturalSort(os.walk(EMDataFolder).next()[1])]

nSections = len(imageFolders)
IJ.log('There are ' + str(nSections) + ' EM layers')

# reading EM metadata
EMMetadataPath = os.path.join(MagCEMFolder, 'EM_Metadata.txt')
try: # old Atlas format
	mosaicMetadata = os.path.join(imageFolders[0] , filter(lambda x: 'Mosaic' in x, os.listdir(imageFolders[0]))[0])
	root = ET.parse(mosaicMetadata).getroot()

	pixelSize = float(root.find('PixelSize').text)
	tileinfo = root.find('TileInfo')
	tileWidth = int(tileinfo.find('TileWidth').text)
	tileHeight = int(tileinfo.find('TileHeight').text)
	tileOverlapX = float(tileinfo.find('TileOverlapXum').text)
Пример #7
0
from java.awt.geom import AffineTransform
from java.awt import Rectangle
from java.util import HashSet, ArrayList
from ini.trakem2 import Project, ControlWindow
from ini.trakem2.display import Patch
from java.util.concurrent.atomic import AtomicInteger

namePlugin = 'alignRigid_EM'
MagCFolder = fc.startPlugin(namePlugin)
ControlWindow.setGUIEnabled(False)
MagC_EM_Folder = os.path.join(MagCFolder, 'MagC_EM','')
MagCParameters = fc.readMagCParameters(MagCFolder)


inputFolder = fc.findFoldersFromTags(MagCFolder, ['export_stitchedEMForAlignment'])[0]
imagePaths = filter(lambda x: os.path.splitext(x)[1] == '.tif', fc.naturalSort([os.path.join(inputFolder, x) for x in os.listdir(inputFolder)]))

regParams = Register_Virtual_Stack_MT.Param()
regParams.minInlierRatio = 0
regParams.registrationModelIndex = 3 # 1-Rigid, 2-Similarity, 3-Affine
regParams.featuresModelIndex = 3

exportForRigidAlignmentFolder = inputFolder
resultRigidAlignmentFolder = fc.mkdir_p(os.path.join(MagC_EM_Folder, 'resultRigidAlignment'))

################################################
# rigid alignment outside trakem2 with register virtual stack plugin because bug in trakem2
transformsPath = os.path.join(MagC_EM_Folder, 'rigidAlignmentTransforms_' + namePlugin + '.txt')
referenceName = fc.naturalSort(os.listdir(exportForRigidAlignmentFolder))[0]
use_shrinking_constraint = 0
IJ.log('Rigid alignment with register virtual stack')