# Path: segmentation/algorithm/slic.py
# def slic(image, num_segments=NUM_SEGMENTS, compactness=COMPACTNESS,
#          max_iterations=MAX_ITERATIONS, sigma=SIGMA,
#          min_size_factor=MIN_SIZE_FACTOR, max_size_factor=MAX_SIZE_FACTOR,
#          enforce_connectivity=CONNECTIVITY):
#     """Segments an image using k-means clustering in Color-(x,y,z) space.
# 
#     Args:
#         image: The image.
#         num_segments: The (approiximate) number of segments in the segmented
#           output image (optional).
#         compactness: Balances color-space proximity and image-space-proximity.
#           Higher values give more weight to image-space proximity (optional).
#         max_iterations: Maximum number of iterations of k-means.
#         sigma: Width of Gaussian kernel used in preprocessing (optional).
#         min_size_factor: Proportion of the minimum segment size to be removed
#           with respect to the supposed segment size
#           `depth*width*height/num_segments` (optional).
#         max_size_factor: Proportion of the maximum connected segment size
#           (optional).
#         enforce_connectivitiy: Whether the generated segments are connected or
#           not (optional).
# 
#     Returns:
#         Integer mask indicating segment labels.
#     """
# 
#     image = tf.cast(image, tf.uint8)
# 
#     def _slic(image):
#         segmentation = skimage_slic(image, num_segments, compactness,
#                                     max_iterations, sigma,
#                                     min_size_factor=min_size_factor,
#                                     max_size_factor=max_size_factor,
#                                     enforce_connectivity=enforce_connectivity,
#                                     slic_zero=False)
#         return segmentation.astype(np.int32)
# 
#     return tf.py_func(_slic, [image], tf.int32, stateful=False, name='slic')


import tensorflow as tf
from .slic import slic



class SlicTest(tf.test.TestCase):

    def test_slic(self):
        image = tf.constant([
            [[255, 255, 255], [255, 255, 255], [0, 0, 0], [0, 0, 0]],
            [[255, 255, 255], [255, 255, 255], [0, 0, 0], [0, 0, 0]],
            [[0, 0, 0], [0, 0, 0], [255, 255, 255], [255, 255, 255]],
            [[0, 0, 0], [0, 0, 0], [255, 255, 255], [255, 255, 255]],
        ])

        expected = [
            [0, 0, 1, 1],
            [0, 0, 1, 1],
            [2, 2, 3, 3],
            [2, 2, 3, 3],
        ]

        with self.test_session() as sess:

# Path: segmentation/algorithm/slic.py
# def slic(image, num_segments=NUM_SEGMENTS, compactness=COMPACTNESS,
#          max_iterations=MAX_ITERATIONS, sigma=SIGMA,
#          min_size_factor=MIN_SIZE_FACTOR, max_size_factor=MAX_SIZE_FACTOR,
#          enforce_connectivity=CONNECTIVITY):
#     """Segments an image using k-means clustering in Color-(x,y,z) space.
# 
#     Args:
#         image: The image.
#         num_segments: The (approiximate) number of segments in the segmented
#           output image (optional).
#         compactness: Balances color-space proximity and image-space-proximity.
#           Higher values give more weight to image-space proximity (optional).
#         max_iterations: Maximum number of iterations of k-means.
#         sigma: Width of Gaussian kernel used in preprocessing (optional).
#         min_size_factor: Proportion of the minimum segment size to be removed
#           with respect to the supposed segment size
#           `depth*width*height/num_segments` (optional).
#         max_size_factor: Proportion of the maximum connected segment size
#           (optional).
#         enforce_connectivitiy: Whether the generated segments are connected or
#           not (optional).
# 
#     Returns:
#         Integer mask indicating segment labels.
#     """
# 
#     image = tf.cast(image, tf.uint8)
# 
#     def _slic(image):
#         segmentation = skimage_slic(image, num_segments, compactness,
#                                     max_iterations, sigma,
#                                     min_size_factor=min_size_factor,
#                                     max_size_factor=max_size_factor,
#                                     enforce_connectivity=enforce_connectivity,
#                                     slic_zero=False)
#         return segmentation.astype(np.int32)
# 
#     return tf.py_func(_slic, [image], tf.int32, stateful=False, name='slic')


# Path: segmentation/algorithm/slic_test.py
import tensorflow as tf
from .slic import slic




class SlicTest(tf.test.TestCase):

    def test_slic(self):
        image = tf.constant([
            [[255, 255, 255], [255, 255, 255], [0, 0, 0], [0, 0, 0]],
            [[255, 255, 255], [255, 255, 255], [0, 0, 0], [0, 0, 0]],
            [[0, 0, 0], [0, 0, 0], [255, 255, 255], [255, 255, 255]],
            [[0, 0, 0], [0, 0, 0], [255, 255, 255], [255, 255, 255]],
        ])

        expected = [
            [0, 0, 1, 1],
            [0, 0, 1, 1],
            [2, 2, 3, 3],
            [2, 2, 3, 3],
        ]

        with self.test_session() as sess:

            segmentation = slic(image, 4)