Skip to content
Snippets Groups Projects
Commit 5108a0b2 authored by Levecque Etienne's avatar Levecque Etienne
Browse files

test: fix a bug with naive offset

parent 876a9efe
No related branches found
No related tags found
No related merge requests found
......@@ -218,8 +218,8 @@ def jpeg_idct_naive(blocks: np.ndarray, quant_tbl: np.ndarray) -> np.ndarray:
Returns: an array with the same shape as blocks with DCT values.
"""
blocks = blocks.astype(float) + 128
return idctn(blocks * quant_tbl.astype(np.uint16), axes=(-2, -1), norm='ortho')
blocks = blocks.astype(float)
return idctn(blocks * quant_tbl.astype(np.uint16), axes=(-2, -1), norm='ortho') + 128
def jpeg_idct_islow(blocks: np.ndarray, quant_tbl: np.ndarray) -> np.ndarray:
......
import numpy as np
import unittest
from antecedent.jpeg_toolbox import llm_dct_islow, jpeg_fdct_islow, define_quant_table, quality_scaling_law, \
quantize_islow_fdct
quantize_islow_fdct, jpeg_fdct_naive, jpeg_idct_naive, jpeg_idct_islow
class TestJPEGToolbox(unittest.TestCase):
......@@ -67,3 +67,10 @@ class TestJPEGToolbox(unittest.TestCase):
quantize_islow_fdct(split_blocks[2], chrominance)],
axis=1)
self.assertTrue(np.allclose(quantized_blocks, split_quantized_blocks))
def test_naive_dct_inversion(self):
quant_tbl = np.ones((8,8), dtype=np.uint16)
blocks = np.random.randint(0, 256, size=(1, 1, 8, 8), dtype=np.int32)
dct = jpeg_fdct_naive(blocks)
spatial = jpeg_idct_naive(dct, quant_tbl=quant_tbl)
self.assertTrue(np.allclose(spatial, blocks))
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment