westoshy
4/23/2017 - 1:51 AM

Scikit-image examples

Scikit-image examples


from skimage import data, segmentation, color
from skimage.future import graph
from matplotlib import pyplot as plt

'''
http://scikit-image.org/docs/dev/auto_examples/segmentation/plot_ncut.html#sphx-glr-auto-examples-segmentation-plot-ncut-py
'''

def normalizedCut(inputImage, c=30, n_seg=400):
    labels1 = segmentation.slic(inputImage, compactness=c, n_segments=n_seg)
    out1 = color.label2rgb(labels1, inputImage, kind='avg')
    g = graph.rag_mean_color(inputImage, labels1, mode='similarity')
    labels2 = graph.cut_normalized(labels1, g)
    out2 = color.label2rgb(labels2, inputImage, kind='avg')

    return out1, out2