コード例 #1
0
# !/usr/bin/python

import os
from neuralimg.image import preproc as pr
from neuralimg.crag.merge_mc import *
""" Generates superpixels given the membrane probabilities """

mask = 7
sigma = 0.25
sps_folder = 'data/crag/sps'
mems_folder = 'data/crag/mem'
mems_norm = 'data/crag/mem_norm'

# Extract images
proc = pr.DatasetProc(mems_folder)
proc.read()
proc.segment(mask, sigma)
proc.save_data(sps_folder)

# Generate normalized membranes [0,1]
proc = pr.DatasetProc(mems_folder)
proc.read()
proc.normalize()
proc.save_data(mems_norm)

# MC Extractor
mc_path = os.path.join(sps_folder, 'histories_mc')
MCTreeExtractor(sps_folder, mems_norm).extract(mc_path)
コード例 #2
0
ファイル: speval.py プロジェクト: juliabuhmann/neuralimg
def get_threshold(mask,
                  sigma,
                  mems,
                  truth,
                  ted_shift,
                  split_bg=False,
                  mweight=10,
                  merge_values=15,
                  stop=False,
                  ted_workers=1,
                  tmp_path=None):
    """ Gets the best threshold in the merge trees computed on the segmentation 
    given by the input parameters 
    Args:
        masks: List of masks to test
        sigmas: List of sigmas to test
        membranes: Membrane predictions
        truth: Folder containing groundtruth images
        ted_shift: minimum shift in the neuron boundaries for considering errors
        split_bg: Whether to split between errors and background errors
        mweight: weight to apply to merges. To be between 1 and 20.
        merge_values: Number of cuts to test for the merge tree histories
        stop: Whether to stop when first minimum found for a given threshold value.
        workers: Number of workers to use. Default: 3
        ted_workers: Number of workers to use for each image evaluation. Should be kept
            low since the total number of threads will be of the order of 
            workers * ted_workers
        tmp_path: Folder to use as temporary path for intermediate files. Set to None 
            to use OS default.
    Return:
        best setting, all settings, sigma and mask
    """
    logging.info('Evaluating sigma %f and mask %d' % (sigma, mask))

    # Prepare temporary folder
    if tmp_path is not None:
        create_dir(tmp_path)
        outp = os.path.join(tmp_path,
                            '_'.join(['s', str(sigma), 'm',
                                      str(mask)]))
        create_dir(outp)
    else:
        outp = tempfile.mkdtemp()

    sps = os.path.join(outp, 'sps')
    hists = os.path.join(outp, 'hists')

    # Save superpixels
    proc = pr.DatasetProc(mems)
    proc.read()
    proc.segment(mask, sigma)
    proc.save_data(sps)

    # Create merge trees
    mt.MCTreeExtractor(sps, mems).extract(hists)

    # Get optimal threshold
    best, all_stats = search_threshold(sps,
                                       truth,
                                       hists,
                                       ted_shift,
                                       mweight,
                                       merge_values,
                                       split_bg,
                                       out_stats=None,
                                       stop=stop,
                                       ted_workers=ted_workers)

    # Clean temporary folder
    shutil.rmtree(outp)

    return best, all_stats, sigma, mask
コード例 #3
0
def generate_superpixels(mask, sigma, mems, sps):
    """ Generates the superpixels in the given folder according to parameters """
    proc = pr.DatasetProc(mems)
    proc.read()
    proc.segment(mask, sigma)
    proc.save_data(sps)
コード例 #4
0
# !/usr/bin/python

from neuralimg.image import preproc as pr
import matplotlib.pyplot as plt

""" Generates superpixels given the membrane probabilities """

proc = pr.DatasetProc('/DataDisk/morad/cremi/superpixels/sampleA/mask3_sigma1_ted25')
proc.read()
sizes, mean, std = proc.compute_supervoxel_stats()

print('Mean: %f, Standard deviation: %f' % (mean, std))

plt.hist(sizes, 50, normed=1, histtype='stepfilled')
plt.show()

コード例 #5
0
# ! /usr/bin/python

from neuralimg.image import preproc as pr
""" Normalizes the membrane probabilities so they are in [0,1] interval """

proc = pr.DatasetProc('data/crag/mem')
proc.read()
proc.normalize()
proc.save_data('data/crag/mem_norm')
コード例 #6
0
# !/usr/bin/python

from neuralimg.image import preproc
""" Preprocesses groundtruth so it joins small supervoxels with neighboring ones
and gives separate ids to unconnected regions even if they belong to the same neuron
(for ease of 2D evaluation) """

# From folder
p = preproc.DatasetProc('data/crag/gt')
p.read()
p.join_small()
p.save_data('data/crag/gt_large')
p.split_labels()
p.save_data('data/crag/gt_large_unconnected')