Beispiel #1
0
    ift.SetSuperpixelIGraphFeatures(igraph, feats, ift.WeightedL2NormPtr(),
                                    0.2, 12.0)
    suppixel = ift.SuperpixelSegmentationByRISF(igraph, opt, img)

    B = ift.Circular(1.5)
    return ift.RelabelRegions(suppixel, B)


if __name__ == '__main__':

    parser = argparse.ArgumentParser(
        prog='Image segmentation using optimum-path trees and seed selection.')
    parser.add_argument('-i',
                        '--input-image',
                        type=check_io_img,
                        required=True)
    parser.add_argument('-n', '--number-superpixels', type=int, required=True)
    parser.add_argument('-o',
                        '--output-image',
                        type=check_aux_img,
                        default='output.pgm',
                        required=False)

    args = parser.parse_args()

    img = ift.ReadImageByExt(args.input_image)
    n = args.number_superpixels
    spxl = RISF(img, n)

    ift.WriteImageByExt(spxl, args.output_image)
Beispiel #2
0
import pyift.pyift as ift
import sys

if __name__ == "__main__":
    if len(sys.argv) != 3:
        print(
            sys.argv[0] +
            " <imagem de entrada (jpg,png,pgm)>  <imagem de saida (jpg,png,pgm)>"
        )
    else:
        img = ift.ReadImageByExt(sys.argv[1])
        A = ift.Rectangular(4, 4)
        img = ift.MeanFilter(img, A)
        A = ift.Rectangular(2, 2)
        img = ift.Erode(img, A, None)
        img = ift.Threshold(img, 0, 220, 255)
        img = ift.Complement(img)
        img = ift.Dilate(img, A, None)
        ift.WriteImageByExt(img, sys.argv[2])
Beispiel #3
0
    seeds_2_dir = sorted([
        pjoin(scrib_2_dir, f) for f in os.listdir(scrib_2_dir)
        if f.endswith('.txt')
    ])

    A = ift.Circular(1.0)

    if not os.path.exists(out_1_dir):
        os.makedirs(out_1_dir)

    if not os.path.exists(out_2_dir):
        os.makedirs(out_2_dir)

    for idx, path in enumerate(origs_dir):

        img = ift.ReadImageByExt(path)
        mimg = ift.ImageToMImage(img, ift.LABNorm_CSPACE)

        seeds_1 = ift.ReadSeeds(img, seeds_1_dir[idx])
        seeds_2 = ift.ReadSeeds(img, seeds_2_dir[idx])

        print('\nSegmenting image {} ...'.format(idx + 1))
        print('Scribbles 1')

        print('Dynamic Tree')
        segm = ift.DynTreeRoot(mimg, A, seeds_1, 1, 0.0, None, 0.0)
        ift.WriteImageByExt(
            ift.Mask(img, segm),
            pjoin(out_1_dir, '{:02d}'.format(idx + 1) + '-dyntree.ppm'))

        print('Dynamic Tree + Neighbor Dist')
Beispiel #4
0
        default=0.5,
        required=False,
        help=
        'Alpha needs to be tuned according to original image and saliency depth.'
    )
    parser.add_argument('-d', '--delta', type=int, default=0, required=False)

    args = parser.parse_args()

    if args.gamma < 0.0:
        raise argparse.ArgumentTypeError('Gamma must be greater than 0.0.')

    if args.alpha < 0.0 or args.alpha > 1.0:
        raise argparse.ArgumentTypeError('Alpha must be between 0.0 and 1.0.')

    orig = ift.ReadImageByExt(args.input_image)
    mrk = ift.ReadImageByExt(args.markers_image)
    seeds = ift.LabeledSetFromSeedImage(mrk, True)

    if args.saliency_image != '':
        objmap = ift.ReadImageByExt(args.saliency_image)
    else:
        objmap = None

    mimg = ift.ImageToMImage(orig, ift.LABNorm_CSPACE)
    A = ift.Circular(1.0)

    if args.closest_root:
        segm = ift.DynTreeClosestRoot(mimg, A, seeds, args.delta, args.gamma,
                                      objmap, args.alpha)
    else:
Beispiel #5
0
        raise argparse.ArgumentTypeError('Auxiliary images must be a .pgm file.')


if __name__ == '__main__':

    parser = argparse.ArgumentParser(prog='Object saliency using optimum-path forest and seed selection.')
    parser.add_argument('-i', '--input-image', type=check_io_img, required=True)
    parser.add_argument('-m', '--markers-image', type=check_aux_img, required=True)
    parser.add_argument('-s', '--superpixel-image', type=check_aux_img, required=True)
    parser.add_argument('-o', '--output-image', type=check_io_img, default='output.pgm', required=False)
    parser.add_argument('-k', '--number-neighbors', type=int, default=24, required=False)
    parser.add_argument('-t', '--threshold', type=float, default=0.8, required=False)

    args = parser.parse_args()

    img = ift.ReadImageByExt(args.input_image)
    mrk = ift.ReadImageByExt(args.markers_image)
    spxl = ift.RelabelImage(ift.ReadImageByExt(args.superpixel_image))
    A = ift.Circular(1.5)
    
    # seed selection
    feat = ift.ExtractImageFeatures(img, spxl, A, False)
    Z = ift.MImageToDataSet(feat, spxl)
    ift.SetStatus(Z, ift.IFT_TRAIN)
    
    graph = ift.CreateKnnGraph(Z, args.number_neighbors)
    ift.UnsupTrain(graph, ift.NormalizedCutPtr())
    
    cluster = ift.DataSetToLabelImage(Z, spxl, False, ift.IFT_GROUP)
    seeds = ift.SelectSeedsForEnhancement(ift.LabeledSetFromSeedImage(mrk, True),
                                          cluster, 1, args.threshold)