我对 Java 和图像处理非常陌生。我正在尝试采用 8*8 块的 DCT(离散余弦变换),然后进行量化,然后通过反量化和 IDCT 获得原始图像。
但是我最终的解码图像在图像的某些区域随机出现绿色、红色和蓝色点,尽管所有原始图像内容都被保留了。我知道这与量化过程中的舍入有关,因为不使用 Math.round 函数会给我正确的原始图片。我无法弄清楚实际原因。您可以在所附图像中看到差异
代码片段:
//Following gives the DCT for 3 buffers with r ,g and b values
temp_DCT_r=FormDCT(temp_DCT_r);
temp_DCT_g=FormDCT(temp_DCT_g);
temp_DCT_b=FormDCT(temp_DCT_b);
//This does the quantization to DCT values for a given
//quantization level
PerformQuantization(temp_DCT_r,Quantization_Level);
PerformQuantization(temp_DCT_g,Quantization_Level);
PerformQuantization(temp_DCT_b,Quantization_Level);
//Following the quantization function
public static void PerformQuantization(double[][] F,int Quantization_Level)
{
int N = 8;
for (int u=0;u<N;u++)
{
for (int v=0;v<N;v++)
{
F[u][v]= Math.round(F[u][v]/(Math.pow(2, Quantization_Level)));
}
}
}