Exemplo n.º 1
0
 def _get_saliency_map(self, type):
     orgb_image = self._get_orgb_image()
     if type == 'raw':
         if self._saliency_map is None:
             small_sigma = self._small_sigma
             large_sigma = self._large_sigma
             self._saliency_map = SightSpotUtil.eval_saliency_map(orgb_image, small_sigma, large_sigma, 'auto')
         return self._saliency_map
     if type == 'precise':
         if self._fusion_map is None:
             saliency_map = self._get_saliency_map(type='raw')
             cell_size = self._cell_size
             alpha = self._SLIC_ALPHA
             iterations = self._ITERATION_NUMBER
             segmentation_map = SightSpotUtil.eval_slic_map(orgb_image, cell_size, alpha, iterations)
             self._fusion_map = SightSpotUtil.combine_saliency_and_segmentation(saliency_map, segmentation_map)
         return self._fusion_map
     raise Exception('Unknown argument value type = "' + str(type) + '"')
Exemplo n.º 2
0
 def _get_saliency_map(self, type):
     orgb_image = self._get_orgb_image()
     if type == 'raw':
         if self._saliency_map is None:
             small_sigma = self._small_sigma
             large_sigma = self._large_sigma
             self._saliency_map = SightSpotUtil.eval_saliency_map(
                 orgb_image, small_sigma, large_sigma, 'auto')
         return self._saliency_map
     if type == 'precise':
         if self._fusion_map is None:
             saliency_map = self._get_saliency_map(type='raw')
             cell_size = self._cell_size
             alpha = self._SLIC_ALPHA
             iterations = self._ITERATION_NUMBER
             segmentation_map = SightSpotUtil.eval_slic_map(
                 orgb_image, cell_size, alpha, iterations)
             self._fusion_map = SightSpotUtil.combine_saliency_and_segmentation(
                 saliency_map, segmentation_map)
         return self._fusion_map
     raise Exception('Unknown argument value type = "' + str(type) + '"')
Exemplo n.º 3
0
    def _get_saliency_map(self, type):
        orgb_image = self._get_orgb_image()
        if type == 'raw':
            if self._saliency_map is None:
                small_sigma = self._small_sigma
                large_sigma = self._large_sigma
                self._saliency_map = SightSpotUtil.eval_saliency_map(orgb_image, small_sigma, large_sigma, 'auto')
            return self._saliency_map
        if type == 'precise':
            if self._fusion_map is None:
                saliency_map = self._get_saliency_map(type='raw')
                cell_size = self._cell_size
                alpha = self._SLIC_ALPHA
                iterations = self._ITERATION_NUMBER
                self._segmentation_map = SightSpotUtil.eval_slic_map(orgb_image, cell_size, alpha, iterations)
                self._fusion_map = SightSpotUtil.combine_saliency_and_segmentation(saliency_map, self._segmentation_map)

                # _visualize_clusters(self._segmentation_map).show('Clusters in random colors')
                # _visualize_contours(self._rgb_image, self._segmentation_map, (255, 255, 0)).show('Cluster contours')
                # _visualize_averaging(self._rgb_image, self._segmentation_map).show('Averaging')
            return self._fusion_map
        raise Exception('Unknown argument value type = "' + str(type) + '"')
Exemplo n.º 4
0
        else:
            avg = numpy.sum(rgb_image[cluster_idx], axis=0) / cluster_size
            palette_items.append(tuple(avg))
    palette = numpy.array(palette_items, dtype='uint8')
    visualization = palette[segmentation_map + 1]
    return Image.fromarray(visualization)


if __name__ == '__main__':
    print 'Segmentation of test image:'
    image = Image.open('flower.jpg')
    rgb_image = numpy.asarray(image, dtype='float32')
    orgb_image = SightSpotUtil.eval_orgb_image(rgb_image)

    start = time.clock()
    segmentation_map = SightSpotUtil.eval_slic_map(orgb_image, 32.0, 0.25, 4)
    print 'Segmentation map extracted in', time.clock() - start, 'sec.'
    print 'Segment number:', numpy.max(segmentation_map) + 1

    _visualize_clusters(segmentation_map).show('Clusters in random colors')
    _visualize_contours(rgb_image, segmentation_map,
                        (255, 255, 0)).show('Cluster contours')
    _visualize_averaging(rgb_image, segmentation_map).show('Averaging')

    print 'Use segmentation to improve clustering...'
    saliency_map = SightSpotUtil.eval_saliency_map(orgb_image, 3.0, 60.0,
                                                   'auto')
    precise_saliency_map = SightSpotUtil.combine_saliency_and_segmentation(
        saliency_map, segmentation_map)
    precise_saliency_image = Image.fromarray(precise_saliency_map * 255)
    precise_saliency_image.show('Pixel-precise saliency image')
Exemplo n.º 5
0
            palette_items.append((0, 0, 0))
        else:
            avg = numpy.sum(rgb_image[cluster_idx], axis=0) / cluster_size
            palette_items.append(tuple(avg))
    palette = numpy.array(palette_items, dtype='uint8')
    visualization = palette[segmentation_map + 1]
    return Image.fromarray(visualization)

if __name__ == '__main__':
    print 'Segmentation of test image:'
    image = Image.open('flower.jpg')
    rgb_image = numpy.asarray(image, dtype='float32')
    orgb_image = SightSpotUtil.eval_orgb_image(rgb_image)

    start = time.clock()
    segmentation_map = SightSpotUtil.eval_slic_map(orgb_image, 32.0, 0.25, 4)
    print 'Segmentation map extracted in', time.clock() - start, 'sec.'
    print 'Segment number:', numpy.max(segmentation_map) + 1

    _visualize_clusters(segmentation_map).show('Clusters in random colors')
    _visualize_contours(rgb_image, segmentation_map, (255, 255, 0)).show('Cluster contours')
    _visualize_averaging(rgb_image, segmentation_map).show('Averaging')

    print 'Use segmentation to improve clustering...'
    saliency_map = SightSpotUtil.eval_saliency_map(orgb_image, 3.0, 60.0, 'auto')
    precise_saliency_map = SightSpotUtil.combine_saliency_and_segmentation(saliency_map, segmentation_map)
    precise_saliency_image = Image.fromarray(precise_saliency_map * 255)
    precise_saliency_image.show('Pixel-precise saliency image')