예제 #1
0
                                     setconcat=setconcat,
                                     openallseries=openallseries,
                                     showomexml=showomexml,
                                     attach=attach,
                                     autoscale=autoscale)

if verbose:
    for k, v in MetaInfo.items():
        log.info(str(k) + ' : ' + str(v))


# do the processing
log.info('Start Processing ...')

if extract_channel:
    imp = MiscTools.splitchannel(imp, channelindex)

# correct background
if correct_background:

    log.info('Removing Background using Rolling Ball ...')
    imp = FilterTools.apply_rollingball(imp,
                                        radius=rb_radius,
                                        createBackground=create_background,
                                        lightBackground=lightbackground,
                                        useParaboloid=useparaboloid,
                                        doPresmooth=dopresmooth,
                                        correctCorners=correct_corners)

# filter image
if filtertype != 'NONE':
예제 #2
0
def run(imagefile, verbose=False):

    # open image file and get a specific series
    log.log(LogLevel.INFO, 'Opening Image: ' + imagefile)
    imp, MetaInfo = ImportTools.openfile(imagefile)

    # output of image metadata in log window
    if verbose:
        for k, v in MetaInfo.items():
            log.log(LogLevel.INFO, str(k) + ' : ' + str(v))

    log.log(LogLevel.INFO, 'File Extension    : ' + MetaInfo['Extension'])
    if 'ResolutionCount' in MetaInfo:
        log.log(LogLevel.INFO,
                'Resolution Count  : ' + str(MetaInfo['ResolutionCount']))
    if 'SeriesCount' in MetaInfo:
        log.log(LogLevel.INFO,
                'SeriesCount       : ' + str(MetaInfo['SeriesCount']))
    if 'SizeC' in MetaInfo:
        log.log(LogLevel.INFO, 'Channel Count     : ' + str(MetaInfo['SizeC']))

    # do the processing
    log.log(LogLevel.INFO, 'Start Processing ...')

    # create empty image list
    imglist_t_c = []
    imglist_t = []
    numch = imp.getNChannels()

    # do the processing
    for t in range(MetaInfo['SizeT']):

        # get the timepoint
        imp_t = getstackfrom5d(imp,
                               MetaInfo,
                               firstC=1,
                               lastC=MetaInfo['SizeC'],
                               firstZ=1,
                               lastZ=MetaInfo['SizeZ'],
                               firstT=t + 1,
                               lastT=t + 1)

        # calc the focus values for the different channels
        for ch in range(numch):

            # get a stack for a channel
            imp_t_c = getstackfrom5d(imp_t,
                                     MetaInfo,
                                     firstC=ch + 1,
                                     lastC=ch + 1,
                                     firstZ=1,
                                     lastZ=MetaInfo['SizeZ'],
                                     firstT=1,
                                     lastT=1)

            # create a name for the plane
            #name = os.path.basename(imagefile) + 'T=' + str(t+1) + '_CH=' + str(ch+1)
            name = 'T=' + str(t + 1) + '_CH=' + str(ch + 1)

            # get the plane with the bst focus to the current timepoint and current channel
            sp_c, fv, fv_max, fv_max_index = calc_focus(imp_t_c, name)
            log.log(LogLevel.INFO, 'Processing TimePoint : ' + str(t + 1))
            log.log(LogLevel.INFO, 'Processing Channel   : ' + str(ch + 1))
            log.log(LogLevel.INFO, 'Max. Value           : ' + str(fv_max))
            log.log(LogLevel.INFO,
                    'Max. Value Slice     : ' + str(fv_max_index))

            # set correct image properties
            sp_c = MiscTools.setproperties(sp_c,
                                           scaleX=MetaInfo['ScaleX'],
                                           scaleY=MetaInfo['ScaleY'],
                                           scaleZ=MetaInfo['ScaleZ'],
                                           unit='micron',
                                           sizeC=1,
                                           sizeZ=1,
                                           sizeT=1)

            imglist_t_c.append(sp_c)

        print 'List CH Stacks :', len(imglist_t_c)

        for i in range(len(imglist_t_c)):
            print str(i) + ' : ', type(imglist_t_c[i])

        # in case of more than one channel use an jarray
        if numch > 1:

            # create an array
            imgarray_c = jarray.array(imglist_t_c, ImagePlus)
            # create an ImageStack from the array
            print 'Type imgarray_c : ', type(imgarray_c)

            for i in range(numch):
                print type(imgarray_c[i])

            imgstack_c = ImageStack.create(imgarray_c)

            # create an ImagePlus object from the jarray
            new_name = os.path.splitext(os.path.basename(imagefile))[0]
            imp_sp_c = ImagePlus(new_name + '_SHARPEST_C', imgstack_c)

        # in case of exactly one channel directly use the ImgPlus
        if numch == 1:
            imp_sp_c = imglist_t_c[0]

        # set correct image properties for the final image
        imp_sp_c = MiscTools.setproperties(imp_sp_c,
                                           scaleX=MetaInfo['ScaleX'],
                                           scaleY=MetaInfo['ScaleY'],
                                           scaleZ=MetaInfo['ScaleZ'],
                                           unit='micron',
                                           sizeC=numch,
                                           sizeZ=1,
                                           sizeT=1)

        # concatenate the timepoints
        imglist_t.append(imp_sp_c)

        if numch > 1:
            # create an array
            imgarray = jarray.array(imglist_t, ImagePlus)
            # create an ImageStack from the array
            imgstack = ImageStack.create(imgarray)
            # create an ImagePlus object from the jarray
            new_name = os.path.splitext(os.path.basename(imagefile))[0]
            imp_sp_t = ImagePlus(new_name + '_SHARPEST_CT', imgstack)

        # in case of exactly one channel directly use the ImgPlus
        if numch == 1:
            imp_sp_t = imglist_t[0]

    return imp_sp_t
예제 #3
0
def run(imagefile,
        outputpath_orig,
        convert_orig2copy=False,
        sft='ome.tiff',
        fillholes=True,
        watershed=True,
        watershed_connectivity=6,
        verbose=True):

    print fillholes, watershed, watershed_connectivity

    # Opening the image
    log.info('Opening Image: ' + imagefile)

    # stitch togehter tiles
    stitchtiles = True

    # when set to True the number of pyramid levels can be read
    setflatres = True

    # select the desired pyramid level - level=0 for full resolution
    readpylevel = 0
    setconcat = True
    openallseries = True
    showomexml = False
    attach = False
    autoscale = True

    # read the image
    imp, MetaInfo = ImportTools.openfile(imagefile,
                                         stitchtiles=stitchtiles,
                                         setflatres=setflatres,
                                         readpylevel=readpylevel,
                                         setconcat=setconcat,
                                         openallseries=openallseries,
                                         showomexml=showomexml,
                                         attach=attach,
                                         autoscale=autoscale)

    if verbose:
        for k, v in MetaInfo.items():
            log.info(str(k) + ' : ' + str(v))

    if EXTRACT_CHANNEL:
        imp = MiscTools.splitchannel(imp, CHINDEX)

    # optional filtering
    if FILTERTYPE != 'NONE':

        log.info('Apply Filter      : ' + FILTERTYPE)
        imp = FilterTools.apply_filter(imp,
                                       radius=FILTER_RADIUS,
                                       filtertype=FILTERTYPE)

    # apply threshold
    log.info('Apply Threshold ...')
    imp = ThresholdTools.apply_threshold(imp,
                                         method=THRESHOLD_METHOD,
                                         background_threshold=THRESHOLD_BGRD,
                                         stackopt=THRESHOLD_STACKOPTION)

    print "3D: ", MetaInfo['is3d']

    # fill holes
    if fillholes:
        imp = BinaryTools.fill_holes(imp, is3d=MetaInfo['is3d'])

        if watershed:
            imp = WaterShedTools.run_watershed(
                imp,
                mj_normalize=True,
                mj_dynamic=1,
                mj_connectivity=watershed_connectivity,
                is3d=MetaInfo['is3d'])

    return imp
background_threshold = 'dark'
#imagefile = r"/datadisk1/tuxedo/Github/Tools_and_Scripts/Fiji/scripts/3d_nuclei_image_holes_T.ome.tiff"
#imagefile = r"/datadisk1/tuxedo/Github/Tools_and_Scripts/Fiji/scripts/3d_nuclei_image_holes.ome.tiff"
imagefile = r"/datadisk1/tuxedo/Github/Tools_and_Scripts/Fiji/scripts/Osteosarcoma_01.ome.tiff"
imagefile = r'"C:\Temp\input\Osteosarcoma_01.ome.tiff"
corrf = 1.0

if stackopt:
	thcmd = method + ' ' + background_threshold + ' stack'
if not stackopt:
	thcmd = method + ' ' + background_threshold

# open image stack
imp, MetaInfo = ImportTools.openfile(imagefile)

imp = MiscTools.splitchannel(imp, 3)

imp = ThresholdTools.apply_threshold(imp,
									 method=method,
									 background_threshold='dark',
									 stackopt=stackopt,
									 corrf=corrf)
											

imp.show()





예제 #5
0
def run(imagefile):

    # open image file and get a specific series
    #imps, MetaInfo = ImportTools.openfile(imagefile)
    imp, MetaInfo = ImportTools.openfile(imagefile,
                                         stitchtiles=True,
                                         setflatres=False,
                                         readpylevel=PYLEVEL,
                                         setconcat=True,
                                         openallseries=True,
                                         showomexml=False,
                                         attach=False,
                                         autoscale=True)

    # Opening the image
    log.info('Opening Image: ' + imagefile)
    log.info('File Extension   : ' + MetaInfo['Extension'])
    if 'ResolutionCount' in MetaInfo:
        log.info('Resolution Count : ' + str(MetaInfo['ResolutionCount']))
    if 'SeriesCount' in MetaInfo:
        log.info('SeriesCount      : ' + str(MetaInfo['SeriesCount']))

    # get sprecifies image series
    #log.info('Getting Image Series : ' + str(IMAGESERIES))
    #imp = ImageTools.getseries(imps, series=IMAGESERIES)

    # do the processing
    log.info('Start Processing ...')

    if BINFACTOR == 1:
        imp_p = imp
    elif BINFACTOR >= 2:
        # apply binning to reduce the image size
        log.info('Apply Binning: ' + str(BINFACTOR) + ' Method : ' + BINMETHOD)
        imp_p = MiscTools.apply_binning(imp,
                                        binning=BINFACTOR,
                                        method=BINMETHOD)

    # apply filter
    log.info('Apply Filter: ' + RANKFILTER)
    imp_p = FilterTools.apply_filter(imp_p, radius=RADIUS)

    # convert to 8-bit for the thresholding
    log.info('Convert to 8-bit ...')
    IJ.run(imp_p, "8-bit", "")

    # apply threshold
    log.info('Apply Threshold: ' + THRESHOLD)
    imp_p = ThresholdTools.apply_threshold(imp_p,
                                           method=THRESHOLD,
                                           background_threshold=THRESHOLD_BGRD,
                                           corrf=CORRFACTOR)

    pastack, results = AnalyzeTools.analyzeParticles(imp_p,
                                                     MINSIZE,
                                                     MAXSIZE,
                                                     MINCIRC,
                                                     MAXCIRC,
                                                     filename=imagefile,
                                                     addROIManager=ROIS)

    # apply suitable LUT to visualize detected particles
    pastack = ImagePlus('Particles', pastack)
    IJ.run(pastack, 'glasbey_inverted', '')
    IJ.run(pastack, 'Enhance Contrast', 'saturated=0.35')

    return pastack, results
예제 #6
0
def run(imagefile, verbose=False):

    # open image file and get a specific series
    log.log(LogLevel.INFO, 'Opening Image: ' + imagefile)
    imp, MetaInfo = ImportTools.openfile(imagefile)

    # output of image metadata in log window
    if verbose:
        for k, v in MetaInfo.items():
            log.log(LogLevel.INFO, str(k) + ' : ' + str(v))

    log.log(LogLevel.INFO, 'File Extension    : ' + MetaInfo['Extension'])
    if 'ResolutionCount' in MetaInfo:
        log.log(LogLevel.INFO,
                'Resolution Count  : ' + str(MetaInfo['ResolutionCount']))
    if 'SeriesCount' in MetaInfo:
        log.log(LogLevel.INFO,
                'SeriesCount       : ' + str(MetaInfo['SeriesCount']))
    if 'SizeC' in MetaInfo:
        log.log(LogLevel.INFO, 'Channel Count     : ' + str(MetaInfo['SizeC']))

    # do the processing
    log.log(LogLevel.INFO, 'Start Processing ...')

    # create empty image list
    imglist = []
    numch = imp.getNChannels()

    # do the processing
    for ch in range(numch):

        # get a channel
        imp_c = MiscTools.splitchannel(imp, ch)
        name = os.path.basename(imagefile) + '_CH=' + str(ch)

        sp, fv, fv_max, fv_max_index = calc_focus(imp_c, name)
        log.log(LogLevel.INFO, 'Processing Channel : ' + str(ch))
        log.log(LogLevel.INFO, 'Max. Value         : ' + str(fv_max))
        log.log(LogLevel.INFO, 'Max. Value Slice   : ' + str(fv_max_index))

        # set correct image properties
        sp = MiscTools.setproperties(sp,
                                     scaleX=MetaInfo['ScaleX'],
                                     scaleY=MetaInfo['ScaleY'],
                                     scaleZ=MetaInfo['ScaleZ'],
                                     unit='micron',
                                     sizeC=1,
                                     sizeZ=1,
                                     sizeT=1)

        imglist.append(sp)

    # in case of more than one channel use an jarray
    if numch > 1:
        # create an array
        imgarray = jarray.array(imglist, ImagePlus)
        # create an ImageStack from the array
        imgstack = ImageStack.create(imgarray)
        # create an ImagePlus object from the jarray
        new_name = os.path.splitext(os.path.basename(imagefile))[0]
        imp_sp = ImagePlus(new_name + '_SHARPEST', imgstack)

    # ic case of exactly one channel directly use the ImgPlus
    if numch == 1:
        imp_sp = imglist[0]

    # set correct image properties for the final image
    imp_sp = MiscTools.setproperties(imp_sp,
                                     scaleX=MetaInfo['ScaleX'],
                                     scaleY=MetaInfo['ScaleY'],
                                     scaleZ=MetaInfo['ScaleZ'],
                                     unit='micron',
                                     sizeC=numch,
                                     sizeZ=1,
                                     sizeT=1)

    return imp_sp
예제 #7
0
def run(imagefile, outputpath_orig, convert_orig2copy=False,
        sft='ome.tiff',
        verbose=False):

    # Opening the image
    log.info('Opening Image: ' + imagefile)

    # stitch togehter tiles
    stitchtiles = True

    # when set to True the number of pyramid levels can be read
    setflatres = True

    # select the desired pyramid level - level=0 for full resolution
    readpylevel = 0
    setconcat = True
    openallseries = True
    showomexml = False
    attach = False
    autoscale = True

    # read the image
    imp, MetaInfo = ImportTools.openfile(imagefile,
                                         stitchtiles=stitchtiles,
                                         setflatres=setflatres,
                                         readpylevel=readpylevel,
                                         setconcat=setconcat,
                                         openallseries=openallseries,
                                         showomexml=showomexml,
                                         attach=attach,
                                         autoscale=autoscale)

    if convert_orig2copy:
        log.info('Detected Extension : ' + MetaInfo['Extension'])
        # check if it was already an OME-TIFF based on the file extension
        ft = ['.ome.tif', '.ome.tiff']

        if MetaInfo['Extension'] in ft:
            """
            # just copy the original file
            new_path = '/output/' + os.path.basename(imagefile)
            command = 'cp ' + imagefile + ' ' + new_path
            log.info('Copy Original file without conversion to output folder')
            os.popen(command)
            """
            # just copy the original file
            new_path = '/output/' + os.path.basename(IMAGEPATH)
            copy_ok = copyorig(IMAGEPATH, new_path, force_overwrite=True)
            log.info(copy_ok)
            
        if MetaInfo['Extension'] not in ft:
            log.info('Converting original to OME-TIFF and save to output folder.')
            savepath_orig = ExportTools.savedata(imp,
                                                 outputpath_orig,
                                                 extension=sft,
                                                 replace=True)

            log.info('Saving converted original image : ' + savepath_orig)

    if verbose:
        for k, v in MetaInfo.items():
            log.info(str(k) + ' : ' + str(v))

    # do the processing
    log.info('Start Processing ...')

    if EXTRACT_CHANNEL:
	    imp = MiscTools.splitchannel(imp, CHINDEX)

    # correct background
    if CORRECT_BACKGROUND:

        log.info('Removing Background using Rolling Ball ...')
        imp = FilterTools.apply_rollingball(imp,
                                            radius=RB_RADIUS,
                                            createBackground=CREATEBACKGROUND,
                                            lightBackground=LIGHTBACKGROUND,
                                            useParaboloid=USEPARABOLOID,
                                            doPresmooth=DOPRESMOOTH,
                                            correctCorners=CORRECTCORNERS)

    # optional filtering
    if FILTERTYPE != 'NONE':

        log.info('Apply Filter      : ' + FILTERTYPE)
        imp = FilterTools.apply_filter(imp,
                                       radius=FILTER_RADIUS,
                                       filtertype=FILTERTYPE)
   
    # apply threshold
    log.info('Apply Threshold ...')
    imp = ThresholdTools.apply_threshold(imp,
                                         method=THRESHOLD_METHOD,
                                         background_threshold=THRESHOLD_BGRD,
                                         stackopt=THRESHOLD_STACKOPTION)

    #ip = imp.getProcessor()
    #ip = ip.convertToByte(False)
    #imp.setProcessor(ip)

    #ImageConverter.setDoScaling(False)
    #ImageConverter(imp).convertToGray8()    

    #imp.show()

    #ImageConverter.setDoScaling(True);
    #IJ.run(imp, "8-bit", "");
    #IJ.run(imp, "Enhance Contrast", "saturated=0.35");
    
    """
    # run watershed on stack
    weights = ChamferWeights3D.BORGEFORS.getFloatWeights()
    normalize = True
    dynamic = 2
    connectivity = 26
    ImageConverter(imp).convertToGray8()
    try:
        dist = BinaryImages.distanceMap(imp, weights, normalize)
    except:
        dist = BinaryImages.distanceMap(imp.getImageStack(), weights, normalize)
    Images3D.invert(dist)
    #imp = ExtendedMinimaWatershed.extendedMinimaWatershed(dist, imp.getImageStack(), dynamic, connectivity, 32, False )
    try:
        imp = ExtendedMinimaWatershed.extendedMinimaWatershed(dist, imp, dynamic, connectivity, 32, False)
    except:
        imp = ExtendedMinimaWatershed.extendedMinimaWatershed(dist,  imp.getImageStack(), dynamic, connectivity, 32, False)
    """

    """
    pastack, results = AnalyzeTools.analyzeParticles(imp, MINSIZE, MAXSIZE, MINCIRC, MAXCIRC,
                                                     filename=imagefile,
                                                     addROIManager=ROIS)

    
    # apply suitable LUT to visualize particles
    pastack = ImagePlus('Particles', pastack)
    IJ.run(pastack, 'glasbey_inverted', '')
    IJ.run(pastack, 'Enhance Contrast', 'saturated=0.35')

    return imp, pastack, results
	"""
    
    return imp
예제 #8
0
# get the base directory
basedir = os.path.dirname(imagefile)
# get the filename without the extension
filename_woext = os.path.splitext(os.path.basename(imagefile))[0]
# create new directories
sourcedir = os.path.join(basedir, 'source')
targetdir = os.path.join(basedir, 'target')
transformdir = os.path.join(basedir, 'transform')

log.info('Base Directory           : ' + basedir)
log.info('Filename wo Extension    : ' + filename_woext)
log.info('Source Directory         : ' + sourcedir)
log.info('Target Directory         : ' + targetdir)
log.info('Transformation Directory : ' + transformdir)

state_sourcedir = MiscTools.createdir(sourcedir)
state_tragetdir = MiscTools.createdir(targetdir)
state_transformdir = MiscTools.createdir(transformdir)

#### Register Slices ####

# save all planes as single images
ExportTools.save_singleplanes(imp,
                              sourcedir,
                              MetaInfo,
                              mode='Z',
                              format='tiff')

featuremodelindex = ["Translation", "Rigid", "Similarity", "Affine"]

regmodelindex = [
예제 #9
0
# get the base directory
basedir = os.path.dirname(imagefile)
# get the filename without the extension
filename_woext = os.path.splitext(os.path.basename(imagefile))[0]
# create new directories
sourcedir = os.path.join(basedir, 'source')
targetdir = os.path.join(basedir, 'target')
transformdir = os.path.join(basedir, 'transform')

log.info('Base Directory           : ' + basedir)
log.info('Filename wo Extension    : ' + filename_woext)
log.info('Source Directory         : ' + sourcedir)
log.info('Target Directory         : ' + targetdir)
log.info('Transformation Directory : ' + transformdir)

state_sourcedir = MiscTools.createdir(sourcedir)
state_tragetdir = MiscTools.createdir(targetdir)
state_transformdir = MiscTools.createdir(transformdir)

#### Register Slices ####

# save all planes as single images
ExportTools.save_singleplanes(imp,
                              sourcedir,
                              MetaInfo,
                              mode='Z',
                              format='tiff')

featuremodelindex = ["Translation", "Rigid", "Similarity", "Affine"]

regmodelindex = [