예제 #1
0
def compress_image_with_dual_reference(im1, reference_image1, reference_image2, block_size=8, single_grid=2, double_grid=2):
    im1_blocks = break_blocks(im1, block_size=8)
    d1 = find_delta(reference_image1, im1)
    d2 = find_delta(reference_image2, im1)
    im1_offsets, im1_residuals = compute_dual_reference(im1_blocks, reference_image1, reference_image2, d1, d2, single_grid=single_grid, double_grid=double_grid)
    im1_residuals_dct = transform(im1_residuals)
    im1_residuals_q = quantize(im1_residuals_dct)
    return im1_offsets, im1_residuals_q
예제 #2
0
def compress_image(im1):
    im1_blocks = break_blocks(im1)
    im1_blocks_dct = transform(im1_blocks)
    im1_blocks_q = quantize(im1_blocks_dct)
    return im1_blocks_q
from our_mpeg import break_blocks, merge_blocks
from our_mpeg import compute_reference, apply_reference
from our_mpeg import transform, inverse_transform
from our_mpeg import quantize, dequantize
from our_mpeg import zigzag, inverse_zigzag

print('loading...', flush=True)
image_data = load(sys.argv[1])
print('finished loading')
sys.stdout.flush()

im1 = image_data[0,0,0]
im2 = image_data[1,0,0]

print('encoding...')
im1_blocks = break_blocks(im1)
im1_offsets, im1_residuals = compute_reference(im1_blocks, im2)
im1_residuals_dct = transform(im1_residuals)
im1_residuals_q = quantize(im1_residuals_dct)
im1_residuals_q_zig = zigzag(im1_residuals_q)
print('finished encoding')

print('decoding...')
im1_residuals_q_dzig = inverse_zigzag(im1_residuals_q_zig)
im1_residuals_dq = dequantize(im1_residuals_q_dzig)
im1_residuals_idct = inverse_transform(im1_residuals_dq)
im1_blocks_recovered = apply_reference(im1_offsets, im1_residuals_idct, im2)
im1_recovered = merge_blocks(im1_blocks_recovered)

print('finished decoding')
예제 #4
0
def compress_image_with_reference(im1, reference_image, block_size=8):
    im1_blocks = break_blocks(im1, block_size=8)
    im1_offsets, im1_residuals = compute_reference(im1_blocks, reference_image)
    im1_residuals_dct = transform(im1_residuals)
    im1_residuals_q = quantize(im1_residuals_dct)
    return im1_offsets, im1_residuals_q
예제 #5
0
import numpy as np
import sys

from our_mpeg import load
from our_mpeg import break_blocks, merge_blocks
from our_mpeg import compute_reference, apply_reference


print('loading...', flush=True)
image_data = load(sys.argv[1])
print('finished loading')
sys.stdout.flush()

test_image_1 = image_data[0,0,0]
test_image_2 = image_data[1,0,0]

print('encoding...')
im1_blocks = break_blocks(test_image_1)
im1_ref    = compute_reference(im1_blocks, test_image_2)
print('finished encoding')

print('decoding...')
im1_blocks_recovered    = apply_reference(im1_ref, test_image_2)

im1_recovered = merge_blocks(im1_blocks_recovered)
print('finished decoding')

print(np.linalg.norm(im1_recovered - test_image_1))