这是DCT的源代码.. !!!未知的4x4 DCT数组将通过在每个块上经过yyang 2x2变换后将4x4数组分成几个块来完成... !!!我想问一下,如何显示已完成但尺寸为4x4转换而不是2x2的数组.. !!!因为仅将其作为条件2x2进行转换,因此一旦转换就恢复为其原始数组大小4x4。请帮忙...!!!

public class Main {
private static final int N = 4;
private static double[][] f = new double[4][4];
private static Random generator = new Random();

public static void main(String[] args) {
    // Generate random integers between 0 and 255
    int value;
    for (int x=0;x<N;x++)
    {
        for (int y=0;y<N;y++)
        {
          value = generator.nextInt(255);
          f[x][y] = value;
          System.out.print(f[x][y]+" ");
        }
         System.out.println();
    }




     DCT dctApplied = new DCT();
    double[][] F = dctApplied.applyDCT(f);
    System.out.println("From f to F");
    System.out.println("-----------");

        for (int i=0;i<2;i++)
        {
          for (int j=0;j<2;j++)
          {

         try {
             System.out.print(F[i][j]+" ");
             }
             catch (Exception e)
             {
                System.out.println(e);
             }

         }
             System.out.println(" ");
        }

}


}

这是针对DCT的源代码

public class DCT {
private static final int N = 2;
private static final int M = 2;

private double[] c = new double[N];

public DCT()
{
      this.initializeCoefficients();
}

private void initializeCoefficients()
{
    for (int i=1;i<N;i++)
    {
        c[i]=1;
    }
    c[0]=1/Math.sqrt(2.0);
}

public double[][] applyDCT(double[][] f)
    {
     double[][] F = new double[4][4];

    for (int row = 0; row < (f.length); row += 2) {
    for (int column = 0; column < f[0].length; column+=2) {
     for (int u=0;u<N;u++)
     {
        for (int v=0;v<N;v++)
         {
           double sum = 0.0;
           for (int i=0;i<N;i++)
           {
             for (int j=0;j<N;j++)
             {
              f[i][j]=f[row+i][column+j];
               sum+=Math.cos(((2*i+1)/(2.0*N))*u*Math.PI)*Math.cos(((2*j+1)/(2.0*N))*v*Math.PI)*f[i][j];
             }
           }
               sum*=((2*c[u]*c[v])/Math.sqrt(M*N));
               F[u][v]=sum;
        }
    }
    }
     }
    return F;
}


}

显示是否执行了上述源代码。
因此,此程序为4x4数组F,然后在F 4x4 4x4数组上进行DCT,但要分成2x2的大小。因此,4x4数组将由4个部分2x2组成,然后对每个部分进行变换,数组F将为f。但是,在显示数组f时,仅显示红色条纹!可能有一个错误,所以请您帮忙...!


这是我想要的程序概述的示例:

最佳答案

尝试这个。更改一下代码:

在主班:

将要打印forF[][]循环的测试部分更改为i<4(代替i<2)和j<4(代替j<2)。

在DCT课程中:

F[u][v] = sum;循环内将F[u+row][v+column] = sum;更改为for

09-04 02:53