Esempio n. 1
0
    def extract(self):
        print 'Action: extract'

        customizableImage = CustomizableImage.load(self.__input)
        width, height = customizableImage.getDimensions()

        transform = WalshHadamardTransform()

        spectralY = customizableImage.getYData()
        if spectralY:
            y = transform.inverseTransformSequence(spectralY)
            y = self.__merge(y, width, height)
            y = np.array(y).reshape(-1).tolist()
            print len(y)
        else:
            y = [0] * (width * height)

        spectralCb = customizableImage.getCbData()
        if spectralCb:
            cb = transform.inverseTransformSequence(spectralCb)
            cb = self.__merge(cb, width, height)
            cb = np.array(cb).reshape(-1).tolist()
            print len(cb)
        else:
            cb = [128] * (width * height)

        spectralCr = customizableImage.getCrData()
        if spectralCr:
            cr = transform.inverseTransformSequence(spectralCr)
            cr = self.__merge(cr, width, height)
            cr = np.array(cr).reshape(-1).tolist()
            print len(cr)
        else:
            cr = [128] * (width * height)

        pixels = map(YCbCrColorModel().getRGB, zip(y, cb, cr))

        bmpImage = BMPImage()
        bmpImage.setDimensions(width, height)
        bmpImage.setRawData(pixels)
        bmpImage.save(self.__output)
Esempio n. 2
0
    def extract(self):
        print 'Action: extract'

        customizable_image = CustomizableImage.load(self.__input)
        width, height = customizable_image.get_dimensions()

        transform = WalshHadamardTransform()

        spectral_y = customizable_image.get_y_data()
        if spectral_y:
            y = transform.inverse_transform_sequence(spectral_y)
            y = self._merge(y, width, height)
            y = np.array(y).reshape(-1).tolist()
            print len(y)
        else:
            y = [0] * (width * height)

        spectral_cb = customizable_image.get_cb_data()
        if spectral_cb:
            cb = transform.inverse_transform_sequence(spectral_cb)
            cb = self._merge(cb, width, height)
            cb = np.array(cb).reshape(-1).tolist()
            print len(cb)
        else:
            cb = [128] * (width * height)

        spectral_cr = customizable_image.get_cr_data()
        if spectral_cr:
            cr = transform.inverse_transform_sequence(spectral_cr)
            cr = self._merge(cr, width, height)
            cr = np.array(cr).reshape(-1).tolist()
            print len(cr)
        else:
            cr = [128] * (width * height)

        pixels = map(YCbCrColorModel().get_rgb, zip(y, cb, cr))

        bmp_image = BMPImage()
        bmp_image.set_dimensions(width, height)
        bmp_image.set_raw_data(pixels)
        bmp_image.save(self.__output)
Esempio n. 3
0
    def compress(self):
        print 'Action: compress'

        bmpImage = BMPImage()
        try:
            bmpImage.load(self.__input)
        except IOError as e:
            print 'IO Error: ' + str(e)
            return

        width, height = bmpImage.getDimensions()
        data = bmpImage.getRawData()

        color = RgbColorModel()
        y, cb, cr = zip(*map(color.getYCbCr, data))

        yBlockSize = 8
        cbBlockSize = 16
        crBlockSize = 16

        y = self.__slice(y, width, height, yBlockSize)
        cb = self.__slice(cb, width, height, cbBlockSize)
        cr = self.__slice(cr, width, height, crBlockSize)

        transform = WalshHadamardTransform()
        spectralY = transform.transformSequence(y)
        spectralCb = transform.transformSequence(cb)
        spectralCr = transform.transformSequence(cr)

        customizableImage = CustomizableImage()
        customizableImage.setDimensions(width, height)
        customizableImage.setDescriptions(
            (yBlockSize, 4, len(spectralY)),
            (cbBlockSize, 4, len(spectralCb)),
            (crBlockSize, 4, len(spectralCr))
        )
        customizableImage.setData(spectralY, spectralCb, spectralCr)
        customizableImage.save(self.__output)
Esempio n. 4
0
    def compress(self):
        print 'Action: compress'

        bmp_image = BMPImage()
        try:
            bmp_image.load(self.__input)
        except IOError as e:
            print 'IO Error: ' + str(e)
            return

        width, height = bmp_image.get_dimensions()
        data = bmp_image.get_raw_data()

        color = RgbColorModel()
        y, cb, cr = zip(*map(color.get_y_cb_cr, data))

        y_block_size = 8
        cb_block_size = 16
        cr_block_size = 16

        y = self._slice(y, width, height, y_block_size)
        cb = self._slice(cb, width, height, cb_block_size)
        cr = self._slice(cr, width, height, cr_block_size)

        transform = WalshHadamardTransform(self.__coeff_removal)
        spectral_y = transform.transform_sequence(y)
        spectral_cb = transform.transform_sequence(cb)
        spectral_cr = transform.transform_sequence(cr)

        customizable_image = CustomizableImage()
        customizable_image.set_dimensions(width, height)
        customizable_image.set_descriptions(
            (y_block_size, 4, len(spectral_y)),
            (cb_block_size, 4, len(spectral_cb)),
            (cr_block_size, 4, len(spectral_cr)))
        customizable_image.set_data(spectral_y, spectral_cb, spectral_cr)
        customizable_image.save(self.__output)