from imagepy.core.engine import Filter
from skimage import data, io, segmentation, color

class SLIC(Filter):
    title = 'SLIC Superpixel'
    note = ['all', 'not_slice', 'auto_snap', 'auto_msk', 'not_channel', 'preview']
    
    para = {'n_segments':100, 'compactness':10.0, 'max_iter':10, 'sigma':0}
    view = [(int, 'n_segments', (1, 1e8), 0, 'segments', 'n'),
            (float, 'compactness', (0.01, 100), 2, 'campactness', 'color-space'),
            (int, 'max_iter', (3, 50), 0, 'max_iter', 'n'),
            (float, 'sigma', (0, 30), 1, 'sigma', 'smooth')]

    def run(self, ips, snap, img, para = None):
        lab = segmentation.slic(snap, para['n_segments'], 
            para['compactness'], para['max_iter'], para['sigma'])
        return color.label2rgb(lab, snap, kind='avg')

class Quickshift(Filter):
    title = 'Quick Shift'
    note = ['all', 'not_slice', 'auto_snap', 'auto_msk', 'not_channel', 'preview']
    
    para = {'ratio':1.0, 'kernel_size':5, 'max_dist':10, 'sigma':0}
    view = [(float, 'ratio', (0, 1), 2, 'ratio', 'color-space'),
            (float, 'kernel_size', (0, 30), 2, 'kernel_size', ''),
            (float, 'max_dist', (1, 1024), 2, 'distance', 'cut off'),
            (float, 'sigma', (0, 30), 1, 'sigma', 'smooth')]

    def run(self, ips, snap, img, para = None):
        lab = segmentation.quickshift(snap, para['ratio'], para['kernel_size'],
            para['max_dist'], para['sigma'])
        return color.label2rgb(lab, snap, kind='avg')

class Felzenszwalb(Filter):
    title = 'Felzenszwalb'
    note = ['all', 'not_slice', 'auto_snap', 'auto_msk', 'not_channel', 'preview']
    
    para = {'scale':1.0, 'sigma':0.8, 'min_size':20}
    view = [(float, 'scale', (0.01, 10), 2, 'scale', ''),
            (float, 'sigma', (0, 30), 2, 'sigma', ''),
            (int, 'min_size', (1, 1024), 0, 'min_size', '')]

    def run(self, ips, snap, img, para = None):
        lab = segmentation.felzenszwalb(snap, para['scale'], para['sigma'], para['min_size'])
        return color.label2rgb(lab, snap, kind='avg')

plgs = [SLIC, Quickshift, Felzenszwalb]
5f65590527df50a89d298920e670c77cff544089
<mask token>


class SLIC(Filter):
    <mask token>
    <mask token>
    <mask token>
    <mask token>
    <mask token>


class Quickshift(Filter):
    title = 'Quick Shift'
    note = ['all', 'not_slice', 'auto_snap', 'auto_msk', 'not_channel',
        'preview']
    para = {'ratio': 1.0, 'kernel_size': 5, 'max_dist': 10, 'sigma': 0}
    view = [(float, 'ratio', (0, 1), 2, 'ratio', 'color-space'), (float,
        'kernel_size', (0, 30), 2, 'kernel_size', ''), (float, 'max_dist',
        (1, 1024), 2, 'distance', 'cut off'), (float, 'sigma', (0, 30), 1,
        'sigma', 'smooth')]

    def run(self, ips, snap, img, para=None):
        lab = segmentation.quickshift(snap, para['ratio'], para[
            'kernel_size'], para['max_dist'], para['sigma'])
        return color.label2rgb(lab, snap, kind='avg')


class Felzenszwalb(Filter):
    title = 'Felzenszwalb'
    note = ['all', 'not_slice', 'auto_snap', 'auto_msk', 'not_channel',
        'preview']
    para = {'scale': 1.0, 'sigma': 0.8, 'min_size': 20}
    view = [(float, 'scale', (0.01, 10), 2, 'scale', ''), (float, 'sigma',
        (0, 30), 2, 'sigma', ''), (int, 'min_size', (1, 1024), 0,
        'min_size', '')]

    def run(self, ips, snap, img, para=None):
        lab = segmentation.felzenszwalb(snap, para['scale'], para['sigma'],
            para['min_size'])
        return color.label2rgb(lab, snap, kind='avg')


<mask token>

<mask token>


class SLIC(Filter):
    <mask token>
    <mask token>
    <mask token>
    <mask token>

    def run(self, ips, snap, img, para=None):
        lab = segmentation.slic(snap, para['n_segments'], para[
            'compactness'], para['max_iter'], para['sigma'])
        return color.label2rgb(lab, snap, kind='avg')


class Quickshift(Filter):
    title = 'Quick Shift'
    note = ['all', 'not_slice', 'auto_snap', 'auto_msk', 'not_channel',
        'preview']
    para = {'ratio': 1.0, 'kernel_size': 5, 'max_dist': 10, 'sigma': 0}
    view = [(float, 'ratio', (0, 1), 2, 'ratio', 'color-space'), (float,
        'kernel_size', (0, 30), 2, 'kernel_size', ''), (float, 'max_dist',
        (1, 1024), 2, 'distance', 'cut off'), (float, 'sigma', (0, 30), 1,
        'sigma', 'smooth')]

    def run(self, ips, snap, img, para=None):
        lab = segmentation.quickshift(snap, para['ratio'], para[
            'kernel_size'], para['max_dist'], para['sigma'])
        return color.label2rgb(lab, snap, kind='avg')


class Felzenszwalb(Filter):
    title = 'Felzenszwalb'
    note = ['all', 'not_slice', 'auto_snap', 'auto_msk', 'not_channel',
        'preview']
    para = {'scale': 1.0, 'sigma': 0.8, 'min_size': 20}
    view = [(float, 'scale', (0.01, 10), 2, 'scale', ''), (float, 'sigma',
        (0, 30), 2, 'sigma', ''), (int, 'min_size', (1, 1024), 0,
        'min_size', '')]

    def run(self, ips, snap, img, para=None):
        lab = segmentation.felzenszwalb(snap, para['scale'], para['sigma'],
            para['min_size'])
        return color.label2rgb(lab, snap, kind='avg')


<mask token>

<mask token>


class SLIC(Filter):
    title = 'SLIC Superpixel'
    note = ['all', 'not_slice', 'auto_snap', 'auto_msk', 'not_channel',
        'preview']
    para = {'n_segments': 100, 'compactness': 10.0, 'max_iter': 10, 'sigma': 0}
    view = [(int, 'n_segments', (1, 100000000.0), 0, 'segments', 'n'), (
        float, 'compactness', (0.01, 100), 2, 'campactness', 'color-space'),
        (int, 'max_iter', (3, 50), 0, 'max_iter', 'n'), (float, 'sigma', (0,
        30), 1, 'sigma', 'smooth')]

    def run(self, ips, snap, img, para=None):
        lab = segmentation.slic(snap, para['n_segments'], para[
            'compactness'], para['max_iter'], para['sigma'])
        return color.label2rgb(lab, snap, kind='avg')


class Quickshift(Filter):
    title = 'Quick Shift'
    note = ['all', 'not_slice', 'auto_snap', 'auto_msk', 'not_channel',
        'preview']
    para = {'ratio': 1.0, 'kernel_size': 5, 'max_dist': 10, 'sigma': 0}
    view = [(float, 'ratio', (0, 1), 2, 'ratio', 'color-space'), (float,
        'kernel_size', (0, 30), 2, 'kernel_size', ''), (float, 'max_dist',
        (1, 1024), 2, 'distance', 'cut off'), (float, 'sigma', (0, 30), 1,
        'sigma', 'smooth')]

    def run(self, ips, snap, img, para=None):
        lab = segmentation.quickshift(snap, para['ratio'], para[
            'kernel_size'], para['max_dist'], para['sigma'])
        return color.label2rgb(lab, snap, kind='avg')


class Felzenszwalb(Filter):
    title = 'Felzenszwalb'
    note = ['all', 'not_slice', 'auto_snap', 'auto_msk', 'not_channel',
        'preview']
    para = {'scale': 1.0, 'sigma': 0.8, 'min_size': 20}
    view = [(float, 'scale', (0.01, 10), 2, 'scale', ''), (float, 'sigma',
        (0, 30), 2, 'sigma', ''), (int, 'min_size', (1, 1024), 0,
        'min_size', '')]

    def run(self, ips, snap, img, para=None):
        lab = segmentation.felzenszwalb(snap, para['scale'], para['sigma'],
            para['min_size'])
        return color.label2rgb(lab, snap, kind='avg')


<mask token>

<mask token>


class SLIC(Filter):
    title = 'SLIC Superpixel'
    note = ['all', 'not_slice', 'auto_snap', 'auto_msk', 'not_channel',
        'preview']
    para = {'n_segments': 100, 'compactness': 10.0, 'max_iter': 10, 'sigma': 0}
    view = [(int, 'n_segments', (1, 100000000.0), 0, 'segments', 'n'), (
        float, 'compactness', (0.01, 100), 2, 'campactness', 'color-space'),
        (int, 'max_iter', (3, 50), 0, 'max_iter', 'n'), (float, 'sigma', (0,
        30), 1, 'sigma', 'smooth')]

    def run(self, ips, snap, img, para=None):
        lab = segmentation.slic(snap, para['n_segments'], para[
            'compactness'], para['max_iter'], para['sigma'])
        return color.label2rgb(lab, snap, kind='avg')


class Quickshift(Filter):
    title = 'Quick Shift'
    note = ['all', 'not_slice', 'auto_snap', 'auto_msk', 'not_channel',
        'preview']
    para = {'ratio': 1.0, 'kernel_size': 5, 'max_dist': 10, 'sigma': 0}
    view = [(float, 'ratio', (0, 1), 2, 'ratio', 'color-space'), (float,
        'kernel_size', (0, 30), 2, 'kernel_size', ''), (float, 'max_dist',
        (1, 1024), 2, 'distance', 'cut off'), (float, 'sigma', (0, 30), 1,
        'sigma', 'smooth')]

    def run(self, ips, snap, img, para=None):
        lab = segmentation.quickshift(snap, para['ratio'], para[
            'kernel_size'], para['max_dist'], para['sigma'])
        return color.label2rgb(lab, snap, kind='avg')


class Felzenszwalb(Filter):
    title = 'Felzenszwalb'
    note = ['all', 'not_slice', 'auto_snap', 'auto_msk', 'not_channel',
        'preview']
    para = {'scale': 1.0, 'sigma': 0.8, 'min_size': 20}
    view = [(float, 'scale', (0.01, 10), 2, 'scale', ''), (float, 'sigma',
        (0, 30), 2, 'sigma', ''), (int, 'min_size', (1, 1024), 0,
        'min_size', '')]

    def run(self, ips, snap, img, para=None):
        lab = segmentation.felzenszwalb(snap, para['scale'], para['sigma'],
            para['min_size'])
        return color.label2rgb(lab, snap, kind='avg')


plgs = [SLIC, Quickshift, Felzenszwalb]

from imagepy.core.engine import Filter
from skimage import data, io, segmentation, color

class SLIC(Filter):
    title = 'SLIC Superpixel'
    note = ['all', 'not_slice', 'auto_snap', 'auto_msk', 'not_channel', 'preview']
    
    para = {'n_segments':100, 'compactness':10.0, 'max_iter':10, 'sigma':0}
    view = [(int, 'n_segments', (1, 1e8), 0, 'segments', 'n'),
            (float, 'compactness', (0.01, 100), 2, 'campactness', 'color-space'),
            (int, 'max_iter', (3, 50), 0, 'max_iter', 'n'),
            (float, 'sigma', (0, 30), 1, 'sigma', 'smooth')]

    def run(self, ips, snap, img, para = None):
        lab = segmentation.slic(snap, para['n_segments'], 
            para['compactness'], para['max_iter'], para['sigma'])
        return color.label2rgb(lab, snap, kind='avg')

class Quickshift(Filter):
    title = 'Quick Shift'
    note = ['all', 'not_slice', 'auto_snap', 'auto_msk', 'not_channel', 'preview']
    
    para = {'ratio':1.0, 'kernel_size':5, 'max_dist':10, 'sigma':0}
    view = [(float, 'ratio', (0, 1), 2, 'ratio', 'color-space'),
            (float, 'kernel_size', (0, 30), 2, 'kernel_size', ''),
            (float, 'max_dist', (1, 1024), 2, 'distance', 'cut off'),
            (float, 'sigma', (0, 30), 1, 'sigma', 'smooth')]

    def run(self, ips, snap, img, para = None):
        lab = segmentation.quickshift(snap, para['ratio'], para['kernel_size'],
            para['max_dist'], para['sigma'])
        return color.label2rgb(lab, snap, kind='avg')

class Felzenszwalb(Filter):
    title = 'Felzenszwalb'
    note = ['all', 'not_slice', 'auto_snap', 'auto_msk', 'not_channel', 'preview']
    
    para = {'scale':1.0, 'sigma':0.8, 'min_size':20}
    view = [(float, 'scale', (0.01, 10), 2, 'scale', ''),
            (float, 'sigma', (0, 30), 2, 'sigma', ''),
            (int, 'min_size', (1, 1024), 0, 'min_size', '')]

    def run(self, ips, snap, img, para = None):
        lab = segmentation.felzenszwalb(snap, para['scale'], para['sigma'], para['min_size'])
        return color.label2rgb(lab, snap, kind='avg')

plgs = [SLIC, Quickshift, Felzenszwalb]