def module_main(ctx):
    try:
        #Inizialization
        print(SEPARATOR)
        print('Saving Database!')

        #Read Parameters
        params = read_params()
        save_database(params['Database'],
                      params['Path'],
                      params['Filename'],
                      to_text=params['Save to text'])

        #Finalization
        print('Object analysis was run successfully!')
        print(SEPARATOR)

    except IOError as e:
        print("Warning: Failed to write to file!!", file=sys.stderr)
        print(str(e), file=sys.stderr)

    except Exception as e:
        error("Error occured while executing '" + str(ctx.type()) +
              "' module '" + str(ctx.name()) + "' !",
              exception=e)
示例#2
0
def module_main(ctx):

    try:
        #Inizialization
        tstart = time.clock()
        print(SEPARATOR)
        print('Colocalization analysis started!')

        #Read Parameters
        print('Reading input parameters!')
        params = read_params()

        output = colocalize(params['ChA Image'],
                            params['ChB Image'],
                            params['ChA'],
                            params['ChB'],
                            params['Ovl'],
                            params['Path'],
                            to_text=params['to_text'],
                            remove_filtered=params['remove_filtered'])

        a3.outputs['Overlapping Image'] = output[0].to_multidimimage()
        a3.outputs['Overlapping Binary'] = VividImage(
            output[0].image > 0, output[0].metadata).to_multidimimage()
        a3.outputs['Overlapping DataBase'] = output[0].database
        #a3.outputs['Channel A Image']=VividImage(output[1].image>0,output[1].metadata).to_multidimimage()
        #a3.outputs['Channel B Image']=VividImage(output[2].image>0,output[2].metadata).to_multidimimage()

        path = a3.Url()
        path.path = output[3]
        a3.outputs['Overlapping Path'] = path

        #Finalization
        tstop = time.clock()
        print('Processing finished in ' + str((tstop - tstart)) + ' seconds! ')
        print('Object analysis was run successfully!')
        print(SEPARATOR)
        quote(verbose=True)
        print(SEPARATOR)

    except IOError as e:
        print("Warning: Failed to write to file!!", file=sys.stderr)
        print(str(e), file=sys.stderr)

    except Exception as e:
        error("Error occured while executing '" + str(ctx.type()) +
              "' module '" + str(ctx.name()) + "' !",
              exception=e)
示例#3
0
def module_main(ctx):
    try:
        #Inizialization
        tstart = time.clock()
        print(SEPARATOR)
        print('Object analysis started!')

        #Read Parameters
        print('Reading input parameters!')
        params = read_params()

        output = analyze_image(params['Source'], params['Mask'],
                               params['Settings'], params['removeFiltered'])

        #Change Name in metadata
        #output.metadata['Name']=params['Mask'].metadata['Name']+'_tagged'

        #Create Output
        a3.outputs['Analyzed Image'] = output.to_multidimimage()
        a3.outputs['Analyzed Binary'] = VividImage(
            output.image > 0, output.metadata).to_multidimimage()
        a3.outputs['Analyzed Database'] = output.database

        #Finalization
        tstop = time.clock()
        print('Processing finished in ' + str((tstop - tstart)) + ' seconds! ')
        print('Object analysis was run successfully!')
        print(SEPARATOR)

    except Exception as e:
        raise error("Error occured while executing '" + str(ctx.type()) +
                    "' module '" + str(ctx.name()) + "' !",
                    exception=e)
示例#4
0
def module_main(ctx):
    
    try:
        filename = a3.inputs['FileName'].path
        
        #Inizialization
        tstart = time.clock()
        print(SEPARATOR)
        print('Loading the following image: ', filename)
        
        #Load and reshape image
        img = VividImage.load(filename, file_type='ome')
        img.reorder('XYZCT')
        
        #Print important image parameters
        print_line_by_line(str(img))
        
        #Create Output
        a3.outputs['Array'] = img.image
        a3.outputs['MetaData']=img.metadata
        
        #Add path and filename to metadata
        a3.outputs['MetaData']['Path']=os.path.dirname(filename)
        a3.outputs['MetaData']['FileName']=os.path.basename(filename)
        
        #Finalization
        tstop = time.clock()
        print('Processing finished in ' + str((tstop - tstart)) + ' seconds! ')
        print('Image loaded successfully!')
        print(SEPARATOR)

    except Exception as e:
        raise error("Error occured while executing '"+str(ctx.type())+"' module '"+str(ctx.name())+"' !",exception=e)
def module_main(ctx):
    try:
        #Inizialization
        tstart = time.clock()
        print(SEPARATOR)
        print('Adaptive thresholding started!')

        #Create Image object
        img = VividImage.from_multidimimage(a3.inputs['Input Image'])

        #Get method and mode
        method = METHODS[a3.inputs['Method'][-1]]

        #Run thresholding
        output_img = adaptive_threshold(img,
                                        method,
                                        blocksize=a3.inputs['BlockSize'],
                                        offset=a3.inputs['Offset'])

        #Change Name in metadata
        #output_img.metadata['Name']=img.metadata['Name']+'_adaptive_thr'

        #Set output
        a3.outputs['Output Image'] = output_img.to_multidimimage()

        #Finalization
        tstop = time.clock()
        print('Processing finished in ' + str((tstop - tstart)) + ' seconds!')
        print('Adaptive thresholding was successfully!')
        print(SEPARATOR)

    except Exception as e:
        raise error("Error occured while executing '" + str(ctx.type()) +
                    "' module '" + str(ctx.name()) + "' !",
                    exception=e)
示例#6
0
def module_main(ctx):

    try:
        #Inizialization
        tstart = time.clock()
        print(SEPARATOR)
        print('Thresholding started!')

        #Create Image object
        img = VividImage.from_multidimimage(a3.inputs['Input Image'])
        print('Thresholding: ' + img.metadata['Name'])

        #Get method and mode. Get kwargs if method is manual
        method = METHODS[a3.inputs['Method'][-1]]
        if method == 'Manual':
            kwargs = {'lower': 0, 'upper': a3.inputs['Manual threshold value']}
        elif method == 'None':
            method = 'Manual'
            kwargs = {'lower': 0, 'upper': 0}
        else:
            kwargs = {}
            if a3.inputs['Slice/Stack histogram']:
                kwargs['mode'] = 'Stack'
            else:
                kwargs['mode'] = 'Slice'
            print('Mode: ' + kwargs['mode'])

        print('Method: ' + method)

        #Run thresholding
        output_img = module_threshold(img, method, kwargs)

        #Change Name in metadata
        #output_img.metadata['Name']=img.metadata['Name']+'_auto_thr'

        #Set output
        a3.outputs['Thresholded Image'] = output_img.to_multidimimage()

        #Finalization
        tstop = time.clock()
        print('Processing finished in ' + str((tstop - tstart)) + ' seconds!')
        print('Autothresholding was successfully!')
        print(SEPARATOR)

    except Exception as e:
        raise error("Error occured while executing '" + str(ctx.type()) +
                    "' module '" + str(ctx.name()) + "' !",
                    exception=e)
示例#7
0
def module_main(ctx):
    try:
        #Inizialization
        tstart = time.clock()
        print(SEPARATOR)

        #Load and reshape image
        ##TempTempTemp##
        img = VividImage(a3.inputs['Image'],
                         copy.deepcopy(a3.inputs['MetaData']))
        #img = Image(a3.inputs['Image'], a3.inputs['MetaData'])
        img.reorder('XYZCT')

        #Get channel from image.
        ch = a3.inputs['Channel']
        print('Loading the following channel: ', img.metadata['Name'][ch])
        if ch >= img.metadata['SizeC']:
            raise Exception('Image has %s channels! Invalid channel %s' %
                            (str(img.metadata['SizeC']), str(ch)))

        #Check if image is time series
        if img.metadata['SizeT'] > 1:
            warning(
                "Image is a time series! Only the first time step will be extracted!",
                file=sys.stderr)

        #Modify metadata
        img.metadata['SamplesPerPixel'] = img.metadata['SamplesPerPixel'][ch]
        img.metadata['Name'] = img.metadata['Name'][ch]
        #img.metadata['Path']=filename

        #Create Output
        #Extract channel from image array
        a3.outputs['Channel 1'] = img.get_dimension(a3.inputs['Channel'],
                                                    'C').to_multidimimage()
        #to_multidimimage(Image(array.astype(np.float),copy.deepcopy(img.metadata)))

        #Finalization
        tstop = time.clock()
        print('Processing finished in ' + str((tstop - tstart)) + ' seconds! ')
        print('Image loaded successfully!')
        print(SEPARATOR)

    except Exception as e:
        raise error("Error occured while executing '" + str(ctx.type()) +
                    "' module '" + str(ctx.name()) + "' !",
                    exception=e)
示例#8
0
def module_main(ctx):
    try:
        #Inizialization
        tstart = time.clock()
        print(SEPARATOR)

        #Create Image object
        img = VividImage.from_multidimimage(a3.inputs['Input Image'])

        # Creatre LogText and start logging
        print('Thresholding: ' + img.metadata['Name'])
        print('Method: Manual')

        #Set upper and lower threshold
        upper = np.amax([a3.inputs['Upper'], a3.inputs['Lower']])
        lower = np.amin([a3.inputs['Upper'], a3.inputs['Lower']])
        print('Settings: \n\t\tUpper:%s \n\t\tLower:%s' %
              (str(upper), str(lower)))

        #Run thresholding
        print('Autothresholding started!')
        output_img = VividImage(threshold_manual(img.array, upper, lower),
                                img.metadata)

        #Set output
        a3.outputs['Output Image'] = output_img.to_multidimimage()

        #Finalization
        tstop = time.clock()
        print('Processing finished in ' + str((tstop - tstart)) + ' seconds!')
        print('Manual thresholding was successfully!')
        print(SEPARATOR)

    except Exception as e:
        raise error("Error occured while executing '" + str(ctx.type()) +
                    "' module '" + str(ctx.name()) + "' !",
                    exception=e)