Exemplo n.º 1
0
def load_single_file(dataset, file_name, n_sp=300, sp='rgb', reorder=None):
    print(file_name)
    image = dataset.get_image(file_name)
    if sp == 'rgb':
        sps = slic_n(image, n_superpixels=n_sp, compactness=10)
    elif sp == 'rgb-skimage':
        sps = slic(image,
                   n_segments=n_sp,
                   compactness=10,
                   multichannel=True,
                   sigma=0.1)
        sps = merge_small_sp(image, morphology.label(sps))[0]
    elif sp == 'rgbd':
        depth = dataset.get_depth(file_name)
        #depth -= depth.min()
        #depth /= depth.max()
        rgbd = np.dstack([image / 255., depth])
        sps = slic(rgbd,
                   n_segments=n_sp,
                   compactness=.1,
                   convert2lab=False,
                   multichannel=True,
                   sigma=0)
        sps = merge_small_sp(image, morphology.label(sps))[0]
    else:
        raise ValueError("Expected sp to be 'rgb' or 'rgbd' got %d" % sp)

    gt = gt_in_sp(dataset, file_name, sps)
    probs = get_probabilities(file_name, dataset.directory)
    if reorder is not None:
        probs = probs[:, :, reorder]
    probs_sp = probabilities_on_sp(dataset, probs, sps)
    return probs_sp, gt, sps
Exemplo n.º 2
0
def load_pascal_single(f, sp_type, which, pascal):
        print(f)
        image = pascal.get_image(f)
        if sp_type == "slic":
            sp = slic_n(image, n_superpixels=100, compactness=10)
            segments = None
        elif sp_type == "cpmc":
            segments, sp = superpixels_segments(f)
            sp, _ = merge_small_sp(image, sp)
            sp = morphological_clean_sp(image, sp, 4)
        else:
            raise ValueError("Expected sp to be 'slic' or 'cpmc', got %s" %
                             sp_type)
        x = get_kraehenbuehl_pot_sp(f, sp)
        if which != "test":
            y = gt_in_sp(pascal, f, sp)
        return x, y, sp, segments
Exemplo n.º 3
0
def eval_segment_best_possible():
    ds = PascalSegmentation()
    print("loading")
    data = load_pascal('train')
    print("getting edges")
    data = add_edges(data)
    print("computing segments")
    segments = [get_km_segments(x, ds.get_image(image_name), sps,
                                n_segments=25) for x, image_name, sps in
                zip(data.X, data.file_names, data.superpixels)]
    print("combining superpixels")
    segments = [seg[sp] for seg, sp in zip(segments, data.superpixels)]
    predictions = [gt_in_sp(ds, f, seg)[seg]
                   for seg, f in zip(segments, data.file_names)]
    Y_true = [ds.get_ground_truth(f) for f in data.file_names]
    hamming, jaccard = eval_on_pixels(ds, Y_true, predictions,
                                      print_results=True)
    tracer()
Exemplo n.º 4
0
def load_single_file(dataset, file_name, n_sp=300, sp='rgb', reorder=None):
    print(file_name)
    image = dataset.get_image(file_name)
    if sp == 'rgb':
        sps = slic_n(image, n_superpixels=n_sp, compactness=10)
    elif sp == 'rgb-skimage':
        sps = slic(image, n_segments=n_sp, compactness=10, multichannel=True, sigma=0.1)
        sps = merge_small_sp(image, morphology.label(sps))[0]
    elif sp == 'rgbd':
        depth = dataset.get_depth(file_name)
        #depth -= depth.min()
        #depth /= depth.max()
        rgbd = np.dstack([image / 255., depth])
        sps = slic(rgbd, n_segments=n_sp, compactness=.1, convert2lab=False, multichannel=True, sigma=0)
        sps = merge_small_sp(image, morphology.label(sps))[0]
    else:
        raise ValueError("Expected sp to be 'rgb' or 'rgbd' got %d" % sp)

    gt = gt_in_sp(dataset, file_name, sps)
    probs = get_probabilities(file_name, dataset.directory)
    if reorder is not None:
        probs = probs[:, :, reorder]
    probs_sp = probabilities_on_sp(dataset, probs, sps)
    return probs_sp, gt, sps