Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I found a blog post that describes the integer based DCT and IDCT <a href="http://fgiesen.wordpress.com/2013/11/04/bink-2-2-integer-dct-design-part-1/" rel="nofollow">here</a> and gives an implementation in Matlab.</p> <p>The code he used is on GitHub, available <a href="https://github.com/rygorous/dct_blog" rel="nofollow">here</a>.</p> <p>I used the method bink_dct_B2.m. This calculates a scaled 1D-DCT transform, so if you want the 2D-orthogonal DCT tranform, you have have to use following code:</p> <pre><code>A_tranformed = (bink_dct_B2(bink_dct_B2(A)')')/8 </code></pre> <p>Here A is the matrix you want to transform. This will give approximately the same output as the Matlab built-in dct2-command (this integer implementation will introduce some rounding-errors).</p> <pre><code>function out=bink_dct_B2(in) % extract rows i0 = in(1,:); i1 = in(2,:); i2 = in(3,:); i3 = in(4,:); i4 = in(5,:); i5 = in(6,:); i6 = in(7,:); i7 = in(8,:); % stage 1 - 8A a0 = i0 + i7; a1 = i1 + i6; a2 = i2 + i5; a3 = i3 + i4; a4 = i0 - i7; a5 = i1 - i6; a6 = i2 - i5; a7 = i3 - i4; % even stage 2 - 4A b0 = a0 + a3; b1 = a1 + a2; b2 = a0 - a3; b3 = a1 - a2; % even stage 3 - 6A 4S c0 = b0 + b1; c1 = b0 - b1; c2 = b2 + b2/4 + b3/2; c3 = b2/2 - b3 - b3/4; % odd stage 2 - 12A 8S % NB a4/4 and a7/4 are each used twice, so this really is 8 shifts, not 10. b4 = a7/4 + a4 + a4/4 - a4/16; b7 = a4/4 - a7 - a7/4 + a7/16; b5 = a5 + a6 - a6/4 - a6/16; b6 = a6 - a5 + a5/4 + a5/16; % odd stage 3 - 4A c4 = b4 + b5; c5 = b4 - b5; c6 = b6 + b7; c7 = b6 - b7; % odd stage 4 - 2A d4 = c4; d5 = c5 + c7; d6 = c5 - c7; d7 = c6; % permute/output out = [c0; d4; c2; d6; c1; d5; c3; d7]; % total: 36A 12S end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload