# Path: segmentation/algorithm/quickshift.py
# def quickshift(image, ratio=RATIO, kernel_size=KERNEL_SIZE,
#                max_distance=MAX_DISTANCE, sigma=SIGMA):
#     """Segments an image using quickshift clustering in Color-(x,y) space.
# 
#     Args:
#         image: The image.
#         ratio: Float in range [0, 1] that balances color-space proximity
#           and image-space-proximity. Higher values give more weight to
#           colorspace (optional).
#         kernel_size: Width of Gaussian kernel used in smoothing the sample
#           density. Higher means fewer clusters (optional).
#         max_distance: Cut-off point for data distances. Higher means fewer
#           clusters (optional).
#         sigma: Width of Gaussian kernel used in preprocessing (optional).
# 
#     Returns:
#         Integer mask indicating segment labels.
#     """
# 
#     image = tf.cast(image, tf.uint8)
# 
#     def _quickshift(image):
#         segmentation = skimage_quickshift(image, ratio, kernel_size,
#                                           max_distance, sigma=sigma)
#         return segmentation.astype(np.int32)
# 
#     # TODO quickshift is stateful?
#     return tf.py_func(_quickshift, [image], tf.int32, stateful=True,
#                       name='quickshift')


import tensorflow as tf
from .quickshift import quickshift



class QuickshiftTest(tf.test.TestCase):

    def test_quickshift(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],
            [1, 1, 0, 0],
            [1, 1, 0, 0],
        ]

        with self.test_session() as sess:

# Path: segmentation/algorithm/quickshift.py
# def quickshift(image, ratio=RATIO, kernel_size=KERNEL_SIZE,
#                max_distance=MAX_DISTANCE, sigma=SIGMA):
#     """Segments an image using quickshift clustering in Color-(x,y) space.
# 
#     Args:
#         image: The image.
#         ratio: Float in range [0, 1] that balances color-space proximity
#           and image-space-proximity. Higher values give more weight to
#           colorspace (optional).
#         kernel_size: Width of Gaussian kernel used in smoothing the sample
#           density. Higher means fewer clusters (optional).
#         max_distance: Cut-off point for data distances. Higher means fewer
#           clusters (optional).
#         sigma: Width of Gaussian kernel used in preprocessing (optional).
# 
#     Returns:
#         Integer mask indicating segment labels.
#     """
# 
#     image = tf.cast(image, tf.uint8)
# 
#     def _quickshift(image):
#         segmentation = skimage_quickshift(image, ratio, kernel_size,
#                                           max_distance, sigma=sigma)
#         return segmentation.astype(np.int32)
# 
#     # TODO quickshift is stateful?
#     return tf.py_func(_quickshift, [image], tf.int32, stateful=True,
#                       name='quickshift')


# Path: segmentation/algorithm/quickshift_test.py
import tensorflow as tf
from .quickshift import quickshift




class QuickshiftTest(tf.test.TestCase):

    def test_quickshift(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],
            [1, 1, 0, 0],
            [1, 1, 0, 0],
        ]

        with self.test_session() as sess:

            segmentation = quickshift(image)