Jump to content

  • Log In with Google      Sign In   
  • Create Account


Quantization scaling for JPEG decoder based on Arai Agui and Nakajima


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 RemcoH   Members   -  Reputation: 149

Like
0Likes
Like

Posted 17 January 2014 - 03:44 PM

Hey people,

 

I'm currently working on a jpeg decoder based on the algorithm of Arai, Agui and Nakajima. While my solution is almost working I am missing a critical scaling operation that is key for this approach (which turns dct values into a dft values). I am supposed to scale the quantization matrix with based on the position of the values in the quantization matrix/ I just can't figure out how to calculate these scaling factors.

 

A good reference I am working with can be found here: http://vsr.informatik.tu-chemnitz.de/~jan/MPEG/HTML/IDCT.html

 

Hoping to find some people that have practical experience with this.

 

Thanks in advance!



Sponsor:

#2 RemcoH   Members   -  Reputation: 149

Like
1Likes
Like

Posted 20 January 2014 - 08:37 AM

Alright... found the solution!biggrin.png

 

In case someone else runs into this, here is how it works. You need to scale the quantization matrices with a value depending on the row and column position of each element in this matrix. The formula for this is:

scaling = 4 / Cu * cos((PI * u) / 16)

The trick is that Cu is 1/sqrt(2) in case u is 0 and 1 in any other case. The scaling must be done for both the row and column. Because I work with 8x8 blocks the pseudo code looks like:

 

// Pre-calculate 1/sqrt(2)
var oneOverSqrtTwo = 0.70710678118654752440084436210485;

// Our quantization is an 1D array with 64 (8x8) elements.
var index = 0;

// Go through all columns.
for (column in 0...8) 
{
     // Calculate scaling for the column and divide by 1/sqrt(2) if needed.
     var columnScaling = 4 * Math.cos(Math.PI * column  * 0.0625);
     if (column == 0) columnScaling /= oneOverSqrtTwo; 

     for (r in 0...8)
     {
          // Calculate scaling for the row and divide by 1/sqrt(2) if needed.
          var rowScaling = 4 * Math.cos(Math.PI * r * 0.0625);
          if (r == 0) rowScaling /= oneOverSqrtTwo;

         // Scale quantization.
         quantization[index] *= rowScaling * columnScaling;

         // Advance the index.
         index ++;
     }
}

 






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS