Abstract:
To reduce artifacts caused by quantization errors in image compression systems, an offset is added to quantized samples at low frequency sections of a macroblock. A decoder uses the offset after decoding to bring the decoded sample closer to the original pre-encoded and pre-quantized sample, thereby compensating for quantization errors.

Description:
PRIORITY CLAIM 
       [0001]    This application claims benefit of and incorporates by reference U.S. Patent Application No. 61/671,683 filed Jul. 14, 2012 entitled “Scalar Quantization Error Reduction by Adding an Offset” by Alireza Shoa Hassani Lashdan. 
     
    
     FIELD OF THE INVENTION 
       [0002]    At least one embodiment of the present invention pertains to image compression, and more particularly but not exclusively, to a system and method for fixed rate image compression that reduces distortion from quantization errors. 
       BACKGROUND 
       [0003]    Quantization is used in compression encoders in order to control output bit rate. Quantization maps a set of input data into a smaller set of quantized data that can be encoded using a lower bit rate. For example, in a quantizer quantized data may be found by: 
         [0000]        Q ( x,q )=( x&gt;&gt; 3) 
         [0004]    And quantization reconstruction values are found from the quantized values by: 
         [0000]        Q   −1 ( x,q )=( x&lt;&lt; 3)+4 
         [0005]    For uniform distribution optimum reconstruction values are the centers of each quantization interval. While the optimum reconstruction values minimize the average distortion they can cause large quantization errors for input values that are close to quantization boundaries. 
         [0006]    Accordingly, a new system and method are needed that reduce quantization errors. 
       SUMMARY 
       [0007]    This summary is provided to introduce in a simplified form certain concepts that are further described in the Detailed Description below and the drawings. This summary is not intended to identify essential features of the claimed subject matter or to limit the scope of the claimed subject matter. 
         [0008]    Embodiments of the invention provide an encoder, computer-readable medium, and method that can reduce the distortion caused by quantization error. In embodiments the quantization reconstruction values are adjusted in order to reduce the quantization error. Embodiments can be employed in a fixed rate image compression algorithm and can reduce the distortion and eliminate noticeable compression artifacts. 
         [0009]    In an embodiment, the encoder comprises a quantization logic, an inverse quantization logic communicatively coupled to the quantization logic, an offset calculation logic communicatively coupled to the inverse quantization logic, and a packet builder. The quantization logic is configured to quantize a sample. The inverse quantization logic is configured to inverse quantize the quantized sample. The offset calculation logic is configured to receive the inverse quantized sample and neighboring inverse quantized samples and to generate, in a macroblock, an offset that can reduce the quantization error for the inverse quantized sample if neighboring inverse quantized samples (e.g., at least one or at least two) have a substantially same value as the inverse quantized sample The packet builder is configured to build a packet using the quantized sample and the generated offset. 
         [0010]    In an embodiment, the method, which the computer-readable medium can store instructions to cause a computer to execute the method, comprises: quantizing a sample; inversing quantization of the quantized sample; receiving the inverse quantized sample and neighboring inverse quantized samples; generating, in a macroblock, an offset for the inverse quantized sample that reduces the quantization error if neighboring inverse quantized samples (e.g., at least one or at least two) have a substantially same value as the inverse quantized sample; and building a packet using the quantized sample and the generated offset. 
         [0011]    In an embodiment, a decoder comprises an inverse quantization logic and an add offset logic communicatively coupled to the inverse quantization logic. The inverse quantization logic is configured to inverse quantize a quantized sample. The add offset logic is configured to add a received offset to the inverse quantized sample. The offset generated at the encoder for a macroblock if neighboring inverse quantized samples have a substantially similar value as the inverse quantized sample. The inverse quantized sample with received offset is substantially similar to an original sample before quantization. 
         [0012]    Other aspects of the encoder, medium, and method will be apparent from the accompanying figures and detailed description. 
     
    
     
       BRIEF DESCRIPTION OF THE DRAWINGS 
         [0013]    One or more embodiments of the present invention are illustrated by way of example and not limitation in the figures of the accompanying drawings, in which like references indicate similar elements. 
           [0014]      FIG. 1  shows quantization reconstructed values after a quantization offset. 
           [0015]      FIG. 2  shows an encoder according to an embodiment of the invention. 
           [0016]      FIG. 3  shows a decoder according to an embodiment of the invention. 
           [0017]      FIG. 4  is a high-level extent diagram showing an example of the architecture of the decoder and/or encoder. 
           [0018]      FIG. 5A  and  FIG. 5B  showing an example of applying the quantization offset using the encoder and decoder of  FIG. 2  and  FIG. 3  respectively. 
           [0019]      FIG. 6  illustrates a technique for reducing quantization error in image compression according to an embodiment of the invention. 
       
    
    
     DETAILED DESCRIPTION 
       [0020]    References in this description to “an embodiment”, “one embodiment”, or the like, mean that the particular feature, function, structure or characteristic being described is included in at least one embodiment of the present invention. Occurrences of such phrases in this specification do not necessarily all refer to the same embodiment. On the other hand, such references are not necessarily mutually exclusive either. 
         [0021]      FIG. 1  shows quantization reconstructed values after a quantization offset using an encoder  200  ( FIG. 2 ) and a decoder  300  ( FIG. 3 ) as will be discussed further below. 
         [0022]      FIG. 2  shows the encoder  200  according to an embodiment of the invention that can generate the offset used in  FIG. 1 . The encoder  200  comprises color space conversion logic  210  communicatively coupled to quantization logic  230 , which is communicatively coupled to both prediction logic  240  and inverse quantization logic  260 . The prediction logic  240  is communicatively coupled to entropy coding logic  250 , which is communicatively coupled to a packet builder  280 . An offset calculation logic  270  is also communicatively coupled to the packet builder  280  and the inverse quantization logic  260 . A rate control logic  220  is coupled to the quantization logic  230 , the prediction logic  240 , and the entropy coding logic  250 . 
         [0023]    In this encoder  200 , a macroblock of, for example, size 2×32, luma and chroma components are compressed into a packet of size 768 bits resulting in a bit rate of 4 bits per component. If the input image sample format is 422 the chroma block size will be 2×16 and the output packet size will be set to 512 bits which results in 4 bits per component. 
         [0024]    The color space conversion logic  210  converts input images that are in RGB color space into YCbCr format. The encoder  200  uses 4 bit coefficients while the decoder  300  uses 15 bit coefficients. The coefficient precision is designed to keep the size of the multipliers small while resulting in less than 1 count of rounding error. 
         [0025]    The quantization logic  230  uses uniform scalar quantization. Multiple quantization step sizes (size of the quantization interval) are used and the rate control uses the smallest quantization step size that satisfies the bit count budget for each packet. For example, for 8 bit images quantization step sizes of 0, 1, 2, 4, 8 and 16 can be used. Quantization also includes a worst case quantization mode. In worst case mode the prediction logic  240  is turned off and input pixels are quantized to 4 or 3 bits and placed directly in a final compressed packet. This mode is only used when prediction is not efficient in compressing data and it ensures that there is a limit to compression distortion when prediction is not helpful. For example for 8 bit pixels that are truncated to 4 bits the distortion is always less than 8 and for 8 bit pixels that are truncated to 3 bits the distortion is always less than 16. 
         [0026]    The prediction logic  240  comprises 3 horizontal prediction modes for the first line and 10 2D prediction modes for the second line. An inter color prediction mode is designed that predicts Cb from Y and Cr from Cb. The prediction logic  240  subtracts the prediction from the quantized samples and calculates the prediction error. For each macroblock a prediction mode for each line and for each color component is found by the rate control  220 . The 3 horizontal prediction modes include the previous pixel and a linear combination of the two previous pixels. The third mode is no prediction which sets the prediction to zero. For the second line the predictions include the top pixel, top left pixel, top right pixel, bottom left pixel, top second left pixel, top second right pixel, a linear combination of the top, top left and left pixels, the average of the top and the top right pixels and the average of the top and the top left pixels. There is also a no prediction mode in which the prediction is set to zero. In the inter-color prediction mode each sample is predicted from the sample that corresponds to the same location but belongs to a different color component by multiplying the sample by a ratio calculated by the rate control block. 
         [0027]    The entropy coding logic  250  comprises two modes: Exp-Golomb coding and a fixed length coding. The fixed length coding is used only when prediction mode is set to “no prediction” and variable length coding is inefficient. Otherwise Exp-Golomb coding is used. The entropy coding logic  250  encodes the prediction errors found by the prediction logic  240 . 
         [0028]    The rate control logic  220  finds the prediction mode and the quantization parameter that result in minimum distortion. Each quantization parameter corresponds to a different quantization step size (i.e. the size of each quantization interval in  FIG. 1 ). Larger quantization parameters correspond to larger quantization intervals which means more quantization. The rate control logic  220  also determines the entropy coding to use. If no combination of prediction mode and quantization parameters result in a bit count that is smaller than the bit count budget for each packet the worst case quantization mode will be used and prediction will be turned off. Finally the offset calculation logic  270  finds the quantization offset that is added to the quantization reconstruction values in order to reduce the quantization error. 
         [0029]    The packet builder logic  280  generates the header of the packet which includes the quantization parameter, prediction modes, entropy coding modes and offset values. It also places the encoded prediction errors into the packet and adds the necessary padding bits to generate 768 bit packets for each macroblock of size 2×32 luma and chroma (444 sample format) or 512 bit packets for macroblocks of size 2×32 luma and 2×16 chroma samples (422 sample format). 
         [0030]    In this image compression encoder  200  each macroblock is encoded independent of other macroblocks. The quantization, prediction and entropy coding modes will be different for different macroblocks and therefore the encoder  200  adapts to local properties of the image. Due to the high output bit rate (4 bits per component) and the number of prediction and entropy coding modes the encoder  200  can achieve visually lossless performance meaning that no noticeable artifacts will occur for natural images and standard test patterns. Since the macroblock height is small and is set to 2 lines this encoder is an ideal choice when low latency is required while no visible compression artifacts are accepted. The fixed bit rate is also a desired feature for many practical applications that require random access or constant bit rate. 
         [0031]    Quantization is used in this encoder  200  to control the bit rate and achieve a fixed bit rate for all macroblocks. In general higher quantization parameters are selected for macroblocks that contain higher frequency components and more detail and texture. However, quantization error in high frequency areas of an image are less noticeable and therefore visually lossless performance can be achieved in these areas. Since prediction is very effective in compressing low frequency areas low quantization parameters will be used for these areas and therefore no visible artifacts will be seen on low frequency areas. Note that high variations in pixel values correspond to high frequency components in frequency domain representation of the image signal. If pixel values are close together or change more gradually this will correspond to lower frequency components. The compression encoder  200  does not need to distinguish between low frequency and high frequency macroblocks. Since encoding is based on predictive coding it performs better (uses less quantization) when pixel values are more predictable, i.e., are close to their neighboring pixels. Therefore in general it uses lower quantization when the macroblock does not contain a lot of high frequencies and it uses larger quantization values when there is many high frequency variations in pixel values and pixels are less predictable. 
         [0032]    Some macroblocks contain both low frequency and high frequency areas. If prediction cannot extract the correlations between samples, these macroblocks may be quantized by large quantization parameters. While large quantization errors in high frequency areas are generally difficult to notice, the quantization errors on low frequency areas can cause visible artifacts. The offset computation logic  270  provides a quantization error reduction feature and reduces the effect of quantization noise in low frequency areas in order to minimize the visible artifacts. This is done by adjusting the quantization reconstruction level for low frequency areas such that the decompressed samples are closer to the original samples. A quantization offset is computed at the encoder  200  for low frequency areas and will be added to the reconstructed samples at the decoder  300 . This will move the reconstruction level for decoded samples and put the reconstruction levels closer to the original samples. Thus, even if large quantization parameters are used the reconstruction levels are placed as close as possible to the original samples in order to reduce the quantization error. 
         [0033]    An example of this is macroblocks that contain a plain background as well as high frequency objects and every pixel in the background has a similar value. When the macroblock is quantized, quantization errors in the background appear like edges and can cause noticeable artifacts. This is more noticeable when large quantization parameters are used and quantization errors are large. However, if the quantization reconstruction value is close to the value of the background pixels, the quantization error will be small even if large quantization parameters are used. The quantization offset ensures that the quantization reconstruction values are placed closer to the original sample values and therefore reduces the quantization error. This is shown in  FIGS. 5A  and B. As can be seen in this figure applying quantization offset reduces the quantization error for the gray area by moving the quantization reconstruction values closer to the actual value of the pixels in the gray areas. 
         [0034]    The offset is more useful when many pixels in the macroblock have the same values after quantization (background pixels). If many pixels have the same value the offset can move the quantization reconstruction value closer to the value of the pixels that have similar quantized value and reduce the quantization error for these pixels. For other pixels in the macroblock for most cases it is better not to add any offset and use the original reconstruction values. Therefore, the offset is calculated only for the samples in the macroblock that have similar values with their neighbors after quantization. The offset calculation logic  270  checks to see if the samples have similar neighbors before computing the offset. Per the equations below if the pixel has the same value as two of its three neighboring pixels it gets the quantization offset otherwise quantization offset is not used for this pixel. For pixels in the first line of the macroblock only the bottom, left and right pixels are used as neighboring pixels and for pixels in the second line pixels from the top, left and right side are used as neighboring pixels. First the values of b i,j  are found for every pixel in the macroblock: 
         [0000]    
       
         
               
               
             
           
               
                   
                   
               
             
             
               
                   
                 b i,j  = 0 
               
               
                   
                 if j = 0 
               
               
                   
                  if i = 0 
               
               
                   
                   if (Q −1 (Q(x i,j ,q),q) = Q −1 (Q(x i,j+1 ,q),q)) or 
               
               
                   
                   (Q −1 (Q(x i,j ,q),q) = Q −1 (Q(x i+1,j ,q),q)) 
               
               
                   
                    b i,j  = 1 
               
               
                   
                   end 
               
               
                   
                  end 
               
               
                   
                  if i = 1 
               
               
                   
                   if (Q −1 (Q(x i,j ,q),q) = Q −1 (Q(x i,j+1 ,q),q)) or 
               
               
                   
                   (Q −1 (Q(x i,j ,q),q) = Q −1 (Q(x i−1,j ,q),q)) 
               
               
                   
                    b i,j  = 1 
               
               
                   
                   end 
               
               
                   
                  end 
               
               
                   
                 end 
               
               
                   
                 if j = L − 1 
               
               
                   
                  if i = 0 
               
               
                   
                   if (Q −1 (Q(x i,j ,q),q) = Q −1 (Q(x i,j−1 ,q),q)) or 
               
               
                   
                   (Q −1 (Q(x i,j ,q),q) = Q −1 (Q(x i+1,j ,q),q)) 
               
               
                   
                    b i,j  = 1 
               
               
                   
                   end 
               
               
                   
                  end 
               
               
                   
                  if i = 1 
               
               
                   
                   if (Q −1 (Q(x i,j ,q),q) = Q −1 (Q(x i,j−1 ,q),q)) or 
               
               
                   
                   (Q −1 (Q(x i,j ,q),q) = Q −1 (Q(x i−1,j ,q),q)) 
               
               
                   
                    b i,j  = 1 
               
               
                   
                   end 
               
               
                   
                  end 
               
               
                   
                 end 
               
               
                   
                 if (j ≠ 0) and (j ≠ L − 1) 
               
               
                   
                  c = 0 
               
               
                   
                  if (Q −1 (Q(x i,j ,q),q) = Q −1 (Q(x i,j+1 ,q),q)) 
               
               
                   
                   c = c + 1 
               
               
                   
                  end 
               
               
                   
                  if (Q −1 (Q(x i,j ,q),q) = Q −1 (Q(x i,j−1 ,q),q )) 
               
               
                   
                   c = c + 1 
               
               
                   
                  end 
               
               
                   
                  if i = 0 
               
               
                   
                   if (Q −1 (Q(x i,j ,q),q) = Q −1 (Q(x i+1,j ,q),q)) 
               
               
                   
                    c = c + 1 
               
               
                   
                   end 
               
               
                   
                  end 
               
               
                   
                  if i = 1 
               
               
                   
                   if (Q −1 (Q(x i,j ,q),q) = Q −1 (Q(x i−1,j ,q),q)) 
               
               
                   
                    c = c + 1 
               
               
                   
                   end 
               
               
                   
                  end 
               
               
                   
                  if (c ≧ 2) 
               
               
                   
                   b i,j  = 1 
               
               
                   
                  end 
               
               
                   
                 end 
               
               
                   
                   
               
             
          
         
       
     
         [0035]    In the above equations x i,j  are the original sample values after color space conversion and L=31 is the length of the macroblock., q is the quantization parameter. Quantization is defined by: 
         [0000]        Q ( x,q )=sign( x )×(| x|&gt;&gt;q )
 
         [0036]    Inverse quantization is calculated by the inverse quantization logic  260  and defined by: 
         [0000]    
       
         
           
             
               
                 Q 
                 
                   - 
                   1 
                 
               
                
               
                 ( 
                 
                   x 
                   , 
                   q 
                 
                 ) 
               
             
             = 
             
               
                 sign 
                  
                 
                   ( 
                   x 
                   ) 
                 
               
               × 
               
                 ( 
                 
                   
                     ( 
                     
                       x 
                        
                       
                         &lt;&lt; 
                         q 
                       
                     
                     ) 
                   
                   + 
                   bias 
                 
                 ) 
               
             
           
         
       
       
         
           
             bias 
             = 
             
               { 
               
                 
                   
                     0 
                   
                   
                     
                       q 
                       = 
                       0 
                     
                   
                 
                 
                   
                     
                       
                         1 
                          
                         
                           &lt;&lt; 
                           
                             ( 
                             
                               q 
                               - 
                               1 
                             
                           
                         
                       
                       ) 
                     
                   
                   
                     otherwise 
                   
                 
               
                
               
                 
 
               
             
           
         
       
     
         [0037]    If b i,j =1 the sample is considered to be part of the background and an offset value can be applied to this sample. In order to find the optimum offset, the following 5 distortion values are computed by the offset calculation logic  270  for each component: 
         [0000]    
       
         
           
             
                 
             
              
             
               
                 d 
                 0 
                 b 
               
               = 
               
                 
                   ∑ 
                   
                     i 
                     = 
                     0 
                   
                   1 
                 
                  
                 
                     
                 
                  
                 
                   
                     ∑ 
                     
                       j 
                       = 
                       0 
                     
                     
                       L 
                       - 
                       1 
                     
                   
                    
                   
                       
                   
                    
                   
                     
                        
                       
                         
                           x 
                           ij 
                         
                         - 
                         
                           
                             Q 
                             
                               - 
                               1 
                             
                           
                            
                           
                             ( 
                             
                               
                                 Q 
                                  
                                 
                                   ( 
                                   
                                     
                                       x 
                                       ij 
                                     
                                     , 
                                     q 
                                   
                                   ) 
                                 
                               
                               , 
                               q 
                             
                             ) 
                           
                         
                       
                        
                     
                     × 
                     
                       b 
                       
                         i 
                         , 
                         j 
                       
                     
                   
                 
               
             
           
         
       
       
         
           
             
                 
             
              
             
               
                 d 
                 0 
               
               = 
               
                 
                   ∑ 
                   
                     i 
                     = 
                     0 
                   
                   1 
                 
                  
                 
                     
                 
                  
                 
                   
                     ∑ 
                     
                       j 
                       = 
                       0 
                     
                     
                       L 
                       - 
                       1 
                     
                   
                    
                   
                       
                   
                    
                   
                      
                     
                       
                         x 
                         ij 
                       
                       - 
                       
                         
                           Q 
                           
                             - 
                             1 
                           
                         
                          
                         
                           ( 
                           
                             
                               Q 
                                
                               
                                 ( 
                                 
                                   
                                     x 
                                     ij 
                                   
                                   , 
                                   q 
                                 
                                 ) 
                               
                             
                             , 
                             q 
                           
                           ) 
                         
                       
                     
                      
                   
                 
               
             
           
         
       
       
         
           
             
               d 
               1 
               b 
             
             = 
             
               { 
               
                 
                   
                     
                       
                         
                           d 
                           0 
                           b 
                         
                       
                       
                         
                           q 
                           ≤ 
                           1 
                         
                       
                     
                     
                       
                         
                           
                             
                               
                                 ∑ 
                                 
                                   i 
                                   = 
                                   0 
                                 
                                 1 
                               
                                
                               
                                   
                               
                                
                               
                                 
                                   ∑ 
                                   
                                     j 
                                     = 
                                     0 
                                   
                                   
                                     L 
                                     - 
                                     1 
                                   
                                 
                                  
                                 
                                     
                                 
                                  
                                 
                                    
                                   
                                     
                                       x 
                                       ij 
                                     
                                     - 
                                     
                                       ( 
                                       
                                         
                                           
                                             Q 
                                             
                                               - 
                                               1 
                                             
                                           
                                            
                                           
                                             ( 
                                             
                                               
                                                 Q 
                                                  
                                                 
                                                   ( 
                                                   
                                                     
                                                       x 
                                                       ij 
                                                     
                                                     , 
                                                     q 
                                                   
                                                   ) 
                                                 
                                               
                                               , 
                                               q 
                                             
                                             ) 
                                           
                                         
                                         + 
                                         
                                           ( 
                                           
                                             1 
                                              
                                             
                                               &lt;&lt; 
                                               
                                                 ( 
                                                 
                                                   q 
                                                   - 
                                                   2 
                                                 
                                               
                                             
                                           
                                           ) 
                                         
                                       
                                       ) 
                                     
                                   
                                   ) 
                                 
                               
                             
                              
                           
                           × 
                           
                             b 
                             
                               i 
                               , 
                               j 
                             
                           
                         
                       
                       
                         
                           q 
                           &gt; 
                           1 
                         
                       
                     
                   
                    
                   
                     
 
                   
                    
                   
                     d 
                     2 
                     b 
                   
                 
                 = 
                 
                   { 
                   
                     
                       
                         
                           
                             
                               d 
                               0 
                               b 
                             
                           
                           
                             
                               q 
                               ≤ 
                               1 
                             
                           
                         
                         
                           
                             
                               
                                 
                                   
                                     ∑ 
                                     
                                       i 
                                       = 
                                       0 
                                     
                                     1 
                                   
                                    
                                   
                                       
                                   
                                    
                                   
                                     
                                       ∑ 
                                       
                                         j 
                                         = 
                                         0 
                                       
                                       
                                         L 
                                         - 
                                         1 
                                       
                                     
                                      
                                     
                                         
                                     
                                      
                                     
                                        
                                       
                                         
                                           x 
                                           ij 
                                         
                                         - 
                                         
                                           ( 
                                           
                                             
                                               
                                                 Q 
                                                 
                                                   - 
                                                   1 
                                                 
                                               
                                                
                                               
                                                 ( 
                                                 
                                                   
                                                     Q 
                                                      
                                                     
                                                       ( 
                                                       
                                                         
                                                           x 
                                                           ij 
                                                         
                                                         , 
                                                         q 
                                                       
                                                       ) 
                                                     
                                                   
                                                   , 
                                                   q 
                                                 
                                                 ) 
                                               
                                             
                                             - 
                                             
                                               ( 
                                               
                                                 1 
                                                  
                                                 
                                                   &lt;&lt; 
                                                   
                                                     ( 
                                                     
                                                       q 
                                                       - 
                                                       1 
                                                     
                                                   
                                                 
                                               
                                               ) 
                                             
                                           
                                           ) 
                                         
                                       
                                       ) 
                                     
                                   
                                 
                                  
                               
                               × 
                               
                                 b 
                                 
                                   i 
                                   , 
                                   j 
                                 
                               
                             
                           
                           
                             
                               q 
                               &gt; 
                               1 
                             
                           
                         
                       
                        
                       
                         
 
                       
                        
                       
                         d 
                         3 
                       
                     
                     = 
                     
                       { 
                       
                         
                           
                             
                               d 
                               0 
                             
                           
                           
                             
                               q 
                               = 
                               0 
                             
                           
                         
                         
                           
                             
                               
                                 
                                   ∑ 
                                   
                                     i 
                                     = 
                                     0 
                                   
                                   1 
                                 
                                  
                                 
                                     
                                 
                                  
                                 
                                   
                                     ∑ 
                                     
                                       j 
                                       = 
                                       0 
                                     
                                     
                                       L 
                                       - 
                                       1 
                                     
                                   
                                    
                                   
                                       
                                   
                                    
                                   
                                      
                                     
                                       
                                         x 
                                         ij 
                                       
                                       - 
                                       
                                         ( 
                                         
                                           
                                             
                                               Q 
                                               
                                                 - 
                                                 1 
                                               
                                             
                                              
                                             
                                               ( 
                                               
                                                 
                                                   Q 
                                                    
                                                   
                                                     ( 
                                                     
                                                       
                                                         x 
                                                         ij 
                                                       
                                                       , 
                                                       q 
                                                     
                                                     ) 
                                                   
                                                 
                                                 , 
                                                 q 
                                               
                                               ) 
                                             
                                           
                                           - 
                                           
                                             ( 
                                             
                                               1 
                                                
                                               
                                                 &lt;&lt; 
                                                 
                                                   ( 
                                                   
                                                     q 
                                                     - 
                                                     1 
                                                   
                                                 
                                               
                                             
                                             ) 
                                           
                                         
                                         ) 
                                       
                                     
                                     ) 
                                   
                                 
                               
                                
                             
                           
                           
                             
                               
                                 q 
                                 &gt; 
                                 0 
                               
                               , 
                             
                           
                         
                       
                     
                   
                 
               
             
           
         
       
     
         [0038]    where x i,j  is the original sample value after color space conversion and q is the quantization parameter. 
         [0039]    The offset calculation logic  270  calculates the quantization offset by: 
         [0000]    
       
         
               
               
             
           
               
                   
                   
               
             
             
               
                   
                 d min  = d 0   b   
               
               
                   
                 offset = 0 
               
               
                   
                 for k = 1 : 2 
               
               
                   
                  if (d k   b  &lt; d min ) 
               
               
                   
                   offset = k 
               
               
                   
                   d min  = d k   b   
               
               
                   
                  end 
               
               
                   
                 end 
               
               
                   
                 if (2×d 3  &lt; d 0 ) 
               
               
                   
                  offset = 3 
               
               
                   
                 end 
               
               
                   
                   
               
             
          
         
       
     
         [0040]    The above operations are done for all components and three offset indexes (offset Y , offset cb , offset Cr ) are computed. These offset values are placed in the header of each packet by the packet builder  280 . An add offset logic of the decoder  300  finds the value of the offset from the offset indexes and adds the offset to the decoded values: 
         [0000]    
       
         
           
             
               x 
               
                 i 
                 , 
                 j 
               
             
             = 
             
               { 
               
                 
                   
                     
                       
                         
                           x 
                           
                             i 
                             , 
                             j 
                           
                         
                       
                       
                         
                           offset 
                           = 
                           0 
                         
                       
                     
                     
                       
                         
                           
                             
                               
                                 x 
                                 
                                   i 
                                   , 
                                   j 
                                 
                               
                               + 
                               
                                 ( 
                                 
                                   1 
                                    
                                   
                                     &lt;&lt; 
                                     
                                       ( 
                                       
                                         q 
                                         - 
                                         2 
                                       
                                     
                                   
                                 
                                 ) 
                               
                             
                             ) 
                           
                           × 
                           
                             b 
                             
                               i 
                               , 
                               j 
                             
                           
                         
                       
                       
                         
                           offset 
                           = 
                           1 
                         
                       
                     
                     
                       
                         
                           
                             
                               
                                 x 
                                 
                                   i 
                                   , 
                                   j 
                                 
                               
                               - 
                               
                                 ( 
                                 
                                   1 
                                    
                                   
                                     &lt;&lt; 
                                     
                                       ( 
                                       
                                         q 
                                         - 
                                         1 
                                       
                                     
                                   
                                 
                                 ) 
                               
                             
                             ) 
                           
                           × 
                           
                             b 
                             
                               i 
                               , 
                               j 
                             
                           
                         
                       
                       
                         
                           offset 
                           = 
                           2 
                         
                       
                     
                     
                       
                         
                           
                             
                               x 
                               
                                 i 
                                 , 
                                 j 
                               
                             
                             - 
                             
                               ( 
                               
                                 1 
                                  
                                 
                                   &lt;&lt; 
                                   
                                     ( 
                                     
                                       q 
                                       - 
                                       2 
                                     
                                   
                                 
                               
                               ) 
                             
                           
                           ) 
                         
                       
                       
                         
                           offset 
                           = 
                           3 
                         
                       
                     
                   
                    
                   
                     
 
                   
                    
                   
                     x 
                     
                       i 
                       , 
                       j 
                     
                   
                 
                 = 
                 
                   
                     clip 
                      
                     
                       ( 
                       
                         
                           x 
                           
                             i 
                             , 
                             j 
                           
                         
                         , 
                         0 
                         , 
                         
                           
                             2 
                             BitDepth 
                           
                           - 
                           1 
                         
                       
                       ) 
                     
                   
                   = 
                   
                     min 
                      
                     
                       ( 
                       
                         
                           max 
                            
                           
                             ( 
                             
                               
                                 x 
                                 
                                   i 
                                   , 
                                   j 
                                 
                               
                               , 
                               0 
                             
                             ) 
                           
                         
                         , 
                         
                           
                             2 
                             BitDepth 
                           
                           - 
                           1 
                         
                       
                       ) 
                     
                   
                 
               
             
           
         
       
     
         [0041]    In the above equations d 0   b  is the distortion for the pixels that are considered to be part of the background and may be modified by the quantization offset when no quantization offset is used. d 1   b  and d 2   b  are the distortions for these pixels if the offset of 1&lt;&lt;(q−2) or −1&lt;&lt;(q−1) are used respectively. If any of these offset values result in a lower distortion than d 0   b  that offset will be used and offset will be set to offset=1 or offset=2 respectively; otherwise offset=0 is used. When offset=0 no offset is added to the decompressed samples which is the most likely case. When offset=1 or 2, the offset value is added to samples which are equal to at least two of their neighboring samples except for the boundaries of the macroblock in which only one of the two available neighbors needs to have the same value. These offsets are useful when the macroblock contains a plain background and high frequency objects and the macroblock is quantized by a high quantization parameter. The offset can reduce the error in the background without having any effect on the higher frequency objects in the macroblock. 
         [0042]    d 0  is the distortion for all pixels in the macroblock without a quantization offset and d 3  is the distortion if an offset of −1&lt;&lt;(q−1) is applied to all pixels in the macroblock. If 2×d 3 &lt;d 0  this offset value is used and we set offset=3. When offset=3, the offset is added to all samples in the macroblock. This mode is designed to improve the performance of multi generation compression. When an image is compressed, decompressed and compressed again it is likely that some macroblocks are quantized by a smaller quantization parameter in the second compression than the quantization parameter used in the first compression. Although the same quantization parameter used in the first compression can meet the bit rate budget and should ideally be selected by the second compression, it is likely that a smaller quantization parameter meets the bit rate budget as well and therefore is selected in the second compression. Since the inverse quantization function adds a bias that depends on the quantization parameter, if a different quantization parameter is used, the second compression will be lossy. The error will be equal to the bias added by inverse quantization which is not random and can add a dc error seen as color or brightness change in the decompressed macroblock. When offset=3 the bias is removed which is almost equivalent to quantization by a larger quantization parameter (the one used in the first compression). 
         [0043]    Note that any offset value that results in noticeable improvement in picture quality can be used. The above offset values and the way they are selected are designed for the encoder  200  and  300  since they reduce most of the noticeable artifacts without adding too much to the complexity of the encoder. But in general other offset values can also be used. 
         [0044]      FIG. 3  shows the decoder  300  according to an embodiment of the invention. As the decoder  300  is substantially the inverse of the encoder  200 , the decoder  300  will not be discussed in further detail. 
         [0045]    The encoder  200  and/or the decoder  300  can be implemented with architecture  400  shown in  FIG. 4 . The architecture  400  includes one or more processors  410  and memory  420  coupled to an interconnect  460 . The interconnect  460  shown in  FIG. 4  is an abstraction that represents any one or more separate physical buses, point-to-point connections, or both, connected by appropriate bridges, adapters, or controllers. The interconnect  460 , therefore, may include, for example, a system bus, a form of Peripheral Component Interconnect (PCI) bus, a HyperTransport or industry standard architecture (ISA) bus, a small computer system interface (SCSI) bus, a universal serial bus (USB), IIC (I2C) bus, or an Institute of Electrical and Electronics Engineers (IEEE) standard 1394 bus, also called “Firewire”, and/or any other suitable form of physical connection. 
         [0046]    The processor(s)  410  is/are the central processing unit (CPU) of the architecture  400  and, thus, control the overall operation of the architecture  400 . In certain embodiments, the processor(s)  410  accomplish this by executing software or firmware stored in memory  420 . The processor(s)  410  may be, or may include, one or more programmable general-purpose or special-purpose microprocessors, digital signal processors (DSPs), programmable controllers, application specific integrated circuits (ASICs), programmable logic devices (PLDs), or the like, or a combination of such devices. 
         [0047]    The memory  420  is or includes the main memory of the architecture  400 . The memory  420  represents any form of random access memory (RAM), read-only memory (ROM), flash memory, or the like, or a combination of such devices. In use, the memory  420  may contain, among other things, software or firmware code for use in implementing at least some of the embodiments of the invention introduced herein. 
         [0048]    Also connected to the processor(s)  410  through the interconnect  460  is a communications interface  440 , such as, but not limited to, a network adapter, one or more output device(s)  430  and one or more input device(s)  450 . The network adapter  240  provides the architecture  200  with the ability to communicate with remote devices and may be, for example, an Ethernet adapter or Fibre Channel adapter. The input device  450  may include a touch screen, keyboard, and/or mouse, etc. The output device  430  may include a screen and/or speakers, etc. 
         [0049]    The techniques introduced above can be implemented by programmable circuitry programmed/configured by software and/or firmware, or entirely by special-purpose circuitry, or by a combination of such forms. Such special-purpose circuitry (if any) can be in the form of, for example, one or more application-specific integrated circuits (ASICs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), etc. 
         [0050]    Software or firmware to implement the techniques introduced here may be stored on a machine-readable storage medium and may be executed by one or more general-purpose or special-purpose programmable microprocessors. A “machine-readable medium”, as the term is used herein, includes any mechanism that can store information in a form accessible by a machine (a machine may be, for example, a computer, network device, cellular phone, personal digital assistant (PDA), manufacturing tool, any device with one or more processors, etc.). For example, a machine-accessible medium includes recordable/non-recordable media (e.g., read-only memory (ROM); random access memory (RAM); magnetic disk storage media; optical storage media; flash memory devices; etc.), etc. 
         [0051]    The term “logic”, as used herein, means: a) special-purpose hardwired circuitry, such as one or more application-specific integrated circuits (ASICs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), or other similar device(s); b) programmable circuitry programmed with software and/or firmware, such as one or more programmed general-purpose microprocessors, digital signal processors (DSPs) and/or microcontrollers, or other similar device(s); or c) a combination of the forms mentioned in a) and b). 
         [0052]      FIG. 6  illustrates a technique  600  for reducing quantization error in image compression according to an embodiment of the invention. In an embodiment, the encoder  200  performs the technique  600  and the decoder  300  performs an inverse of the technique  600 . First, if needed, the color space conversion logic  210  converts ( 610 ) input images that are in RGB color space into YCbCr format. 
         [0053]    Next, the rate control logic  220  determines ( 620 ,  630 ) the quantization parameter and prediction mode that yields minimal distortion and whether the worst case quantization mode needs to be used or not. Quantization and prediction are then applied ( 640 ,  650 ). After, the resulting data are entropy encoded ( 660 ) by the entropy coding logic  250  using an entropy coding mode determined by the rate control  220 . An offset is then calculated ( 670 ) by the offset calculation logic  270  and the packet is assembled ( 680 ) by the packet builder. The method  600  then ends. 
         [0054]    Note that any and all of the embodiments described above can be combined with each other, except to the extent that it may be stated otherwise above or to the extent that any such embodiments might be mutually exclusive in function and/or structure. 
         [0055]    Although the present invention has been described with reference to specific exemplary embodiments, it will be recognized that the invention is not limited to the embodiments described, but can be practiced with modification and alteration within the spirit and scope of the appended claims. Accordingly, the specification and drawings are to be regarded in an illustrative sense rather than a restrictive sense.