Пример #1
0
    def bfexporter(imp, savepath, useLOCI=True):

        if useLOCI:

            paramstring = "outfile=[" + savepath + "] windowless=true compression=Uncompressed saveROI=false"
            plugin = LociExporter()
            plugin.arg = paramstring
            exporter = Exporter(plugin, imp)
            exporter.run()

        # save as OME-TIFF using BioFormats library using the IJ.run method
        if not useLOCI:

            # 2019-04-25: This does not seem to work in headless anymore
            paramstring = "save=[" + savepath + "] compression=Uncompressed"
            IJ.run(imp, "Bio-Formats Exporter", paramstring)

        return paramstring
Пример #2
0
#@String round_or_square
#@String final_tile_size
#@String xoffset_tiles
#@String yoffset_tiles
#@String compress

from ij import IJ, WindowManager
import os
import string
import sys
import time

from loci.plugins.out import Exporter
from loci.plugins import LociExporter

plugin = LociExporter()


def tiffextend(imname):
    if '.tif' in imname:
        return imname
    if '.' in imname:
        return imname[:imname.index('.')] + '.tiff'
    else:
        return imname + '.tiff'


def savefile(im, imname, plugin, compress='false'):
    attemptcount = 0
    imname = tiffextend(imname)
    print('Saving ', imname, im.width, im.height)
Пример #3
0
# run image analysis pipeline
filtered_image = run(IMAGEPATH,
                     useBF=True,
                     series=0)

# get time at the end and calc duration of processing
end = time.clock()
log.info('Duration of whole Processing : ' + str(end - start))

###########################################################

start = time.clock()

# create the argument string for the BioFormats Exporter and save as OME.TIFF
paramstring = "outfile=" + outputimagepath + " " + "windowless=true compression=Uncompressed saveROI=false"
plugin = LociExporter()
plugin.arg = paramstring
exporter = Exporter(plugin, filtered_image)
exporter.run()

# get time at the end and calc duration of processing
end = time.clock()
log.info('Duration of saving as OME-TIFF : ' + str(end - start))

# show the image
filtered_image.show()

# finish
log.info('Done.')
Пример #4
0
def main():

    # Get active dataset
    #img = IJ.getImage()
    display = displayservice.getActiveDisplay()
    active_dataset = imagedisplayservice.getActiveDataset(display)

    if not active_dataset:
        IJ.showMessage('No image opened.')
        return

    # Get image path
    fname = active_dataset.getSource()
    dir_path = os.path.dirname(fname)

    if not fname:
        IJ.showMessage('Source image needs to match a file on the system.')
        return

    # Open ROIs
    rois = RoiManager.getInstance()
    if not rois:
        roi_path = os.path.join(dir_path, "RoiSet.zip")
        if not os.path.isfile(roi_path):
            try:
                roi_path = glob.glob(os.path.join(dir_path, "*.roi"))[0]
            except:
                roi_path = None

        if not roi_path:
            IJ.showMessage('No ROIs. Please use Analyze > Tools > ROI Manager...')
            return

        rois = RoiManager(True)
        rois.reset()
        rois.runCommand("Open", roi_path)

    IJ.log('Image filename is %s' % fname)
    dt = get_dt(active_dataset)

    rois_array = rois.getRoisAsArray()
    for i, roi in enumerate(rois_array):

        crop_id = i + 1
        IJ.log("Croping %i / %i" % (crop_id, len(rois_array)))

        # Get filename and basename of the current cropped image
        crop_basename = "crop%i_%s" % (crop_id, active_dataset.getName())
        crop_basename = os.path.splitext(crop_basename)[0] + ".ome.tif"
        crop_fname = os.path.join(os.path.dirname(fname), crop_basename)

        # Get bounds and crop
        bounds = roi.getBounds()
        dataset = crop(ij, datasetservice, active_dataset,
                       bounds.x, bounds.y, bounds.width,
                       bounds.height, crop_basename)

        # Show cropped image
        ij.ui().show(dataset.getName(), dataset)

        # Save cropped image (ugly hack)
        IJ.log("Saving crop to %s" % crop_fname)

        imp = IJ.getImage()
        bfExporter = LociExporter()
        macroOpts = "save=[" + crop_fname + "]"
        bfExporter.setup(None, imp)
        Macro.setOptions(macroOpts)
        bfExporter.run(None)

        imp.close()

    IJ.log('Done')