コード例 #1
0
ファイル: compose.py プロジェクト: afcarl/procgraph
    def update(self):
        width = self.get_config('width')
        height = self.get_config('height')

        canvas = np.zeros((height, width, 3), dtype='uint8')

        positions = self.get_config('positions')

        if not isinstance(positions, dict):
            raise Exception('I expected a dict, not "%s"' % positions)

        for signal, position in positions.items():
            if not self.is_valid_input_name(signal):
                raise Exception('Unknown input "%s" in %s.' % (signal, self))
            rgb = self.get_input(signal)
            # TODO check
            if rgb is not None:
                assert_rgb_image(rgb, 'input %s to compose block' % signal)

                place_at(canvas, rgb, position[0], position[1])
                #print "Writing image %s" % signal
            else:
                print "Ignoring image %s because not ready.\n" % signal

        self.set_output(0, canvas)
コード例 #2
0
ファイル: compose.py プロジェクト: AndreaCensi/procgraph
    def update(self):
        width = self.get_config('width')
        height = self.get_config('height')

        canvas = np.zeros((height, width, 3), dtype='uint8')

        positions = self.get_config('positions')

        if not isinstance(positions, dict):
            raise Exception('I expected a dict, not "%s"' % positions)

        for signal, position in positions.items():
            if not self.is_valid_input_name(signal):
                raise Exception('Unknown input "%s" in %s.' % (signal, self))
            rgb = self.get_input(signal)
            # TODO check
            if rgb is not None:
                assert_rgb_image(rgb, 'input %s to compose block' % signal)

                place_at(canvas, rgb, position[0], position[1])
                #print "Writing image %s" % signal
            else:
                print "Ignoring image %s because not ready.\n" % signal

        self.set_output(0, canvas)
コード例 #3
0
def rgb2gray(rgb):
    ''' Converts a HxWx3 RGB image into a HxW grayscale image 
        by computing the luminance. 
        
        :param rgb: RGB image
        :type rgb: array[HxWx3](uint8),H>0,W>0
        
        :return: A RGB image in shades of gray.
        :rtype: array[HxW](uint8)
    '''
    assert_rgb_image(rgb, 'input to rgb2grayscale')
    r = rgb[:, :, 0].squeeze()
    g = rgb[:, :, 1].squeeze()
    b = rgb[:, :, 2].squeeze()
    # note we keep a uint8
    gray = r * 299.0 / 1000 + g * 587.0 / 1000 + b * 114.0 / 1000
    gray = gray.astype('uint8')

    return gray
コード例 #4
0
def rgb2gray(rgb):
    ''' Converts a HxWx3 RGB image into a HxW grayscale image 
        by computing the luminance. 
        
        :param rgb: RGB image
        :type rgb: array[HxWx3](uint8),H>0,W>0
        
        :return: A RGB image in shades of gray.
        :rtype: array[HxW](uint8)
    '''
    assert_rgb_image(rgb, 'input to rgb2grayscale')
    r = rgb[:, :, 0].squeeze()
    g = rgb[:, :, 1].squeeze()
    b = rgb[:, :, 2].squeeze()
    # note we keep a uint8
    gray = r * 299.0 / 1000 + g * 587.0 / 1000 + b * 114.0 / 1000
    gray = gray.astype('uint8')

    return gray
コード例 #5
0
def posterize(rgb, levels=2):
    ''' 
        Posterizes the given image with the specified number of levels.
        
        :param rgb: RGB image
        :type rgb: array(HxWx3,uint8),H>0,W>0
    
        :param levels: number of levels
        :type levels: int,>=2
        
        :return: A RGB image with the specified number of levels.
        :rtype: array(HxWx3,uint8)
    '''
    assert_rgb_image(rgb, 'input to rgb2grayscale')

    result = numpy.zeros(shape=rgb.shape, dtype='uint8')
    for i in range(3):
        channel = rgb[:, :, i].squeeze()
        result[:, :, i] = posterize_channel(channel, levels)

    return result
コード例 #6
0
def posterize(rgb, levels=2):
    ''' 
        Posterizes the given image with the specified number of levels.
        
        :param rgb: RGB image
        :type rgb: array(HxWx3,uint8),H>0,W>0
    
        :param levels: number of levels
        :type levels: int,>=2
        
        :return: A RGB image with the specified number of levels.
        :rtype: array(HxWx3,uint8)
    '''
    assert_rgb_image(rgb, 'input to rgb2grayscale')

    result = np.zeros(shape=rgb.shape, dtype='uint8')
    for i in range(3):
        channel = rgb[:, :, i].squeeze()
        result[:, :, i] = posterize_channel(channel, levels)

    return result