Exemple #1
0
def frontend_transform(blockr, blockg, blockb, N=8):
    """Software implementation of the frontend part"""
    ycbcr_blocks = [[[] for _ in range(N)] for _ in range(3)]
    dct_blocks, dct_blocks_linear, zig_zag_blocks = [[] for _ in range(3)]
    """Color space conversion"""
    for i in range(N):
        for j in range(N):
            red = blockr[i][j]
            green = blockg[i][j]
            blue = blockb[i][j]
            color_convert_obj = ColorSpace(red, green, blue)
            ycbcr = color_convert_obj.get_jfif_ycbcr()
            ycbcr = ycbcr.tolist()
            for k in range(3):
                ycbcr_blocks[k][i].append(ycbcr[k][0])

    for i in range(3):
        """dct-2d transformation"""
        dct_blocks.append(
            dct_2d_transformation(N).dct_2d_transformation(ycbcr_blocks[i]))
        """dct blocks to linear lists"""
        dct_blocks_linear.append(list(chain.from_iterable(dct_blocks[i])))
        """zig zag scan"""
        zig_zag_blocks.append(zig_zag_scan(N).zig_zag(dct_blocks_linear[i]))

    return zig_zag_blocks
Exemple #2
0
def frontend_transform(blockr, blockg, blockb, N=8):
    """Software implementation of the frontend part"""
    ycbcr_blocks = [[[] for _ in range(N)] for _ in range(3)]
    dct_blocks, dct_blocks_linear, zig_zag_blocks = [[] for _ in range(3)]

    """Color space conversion"""
    for i in range(N):
        for j in range(N):
            red = blockr[i][j]
            green = blockg[i][j]
            blue = blockb[i][j]
            color_convert_obj = ColorSpace(red, green, blue)
            ycbcr = color_convert_obj.get_jfif_ycbcr()
            ycbcr = ycbcr.tolist()
            for k in range(3):
                ycbcr_blocks[k][i].append(ycbcr[k][0])

    for i in range(3):
        """dct-2d transformation"""
        dct_blocks.append(dct_2d_transformation(N).dct_2d_transformation(ycbcr_blocks[i]))
        """dct blocks to linear lists"""
        dct_blocks_linear.append(list(chain.from_iterable(dct_blocks[i])))
        """zig zag scan"""
        zig_zag_blocks.append(zig_zag_scan(N).zig_zag(dct_blocks_linear[i]))

    return zig_zag_blocks
Exemple #3
0
 def initialize(self):
     """Initialize the inputs and outputs"""
     for i in range(self.samples):
         r, g, b = [randrange(256) for _ in range(3)]
         a = ColorSpace(r, g, b)
         y, cb, cr = [a.get_jfif_ycbcr()[j] for j in range(3)]
         for color, val in zip(('red', 'green', 'blue'), (r, g, b)):
             self.inputs[color].append(val)
         for ycbcr_out, val in zip(('y', 'cb', 'cr'),
                                   (int(y), int(cb), int(cr))):
             self.expected_outputs[ycbcr_out].append(val)
 def initialize(self):
     """Initialize the inputs and outputs"""
     for i in range(self.samples):
         r, g, b = [randrange(256) for _ in range(3)]
         a = ColorSpace(r, g, b)
         y, cb, cr = [a.get_jfif_ycbcr()[j] for j in range(3)]
         for color, val in zip(('red', 'green', 'blue'), (r, g, b)):
             self.inputs[color].append(val)
         for ycbcr_out, val in zip(('y', 'cb', 'cr'),
                                   (int(y), int(cb), int(cr))):
             self.expected_outputs[ycbcr_out].append(val)