Example #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
Example #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
Example #3
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
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')

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