【发布时间】:2015-02-21 23:25:05
【问题描述】:
这是源代码 DCT .. !!! 4x4 DCT 的未知数组将通过将 4x4 数组拆分为几个块来完成,每个块上的 yyang 2x2 变换...!!!我想问一下,如何显示一个已经完成的数组,但是大小是 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 时,只出现红色条纹!可能有错误,所以我请帮助......!
这是我想要的程序概述的示例:
【问题讨论】:
-
所以你想打印从函数
applyDCT()返回的数组?要显示矩阵,请在行中使用\t作为制表符,在行尾使用\n作为新行。 -
在DCT过程中,4x4数组在DCT变换中被分割成2x2块……!!!但我问如何显示一个转换回 4x4 数组的数组
-
你能举个例子吗?
-
以图片为例
-
所以这就是我的理解:你在
applyDCT函数中初始化F[][]作为4*4 数组但你的u和v总是从0 to 2和F[u][v] = sum;将始终更新F[][]的块 1 部分。所以我认为你应该把它改成F[u+row][v+column] = sum;。然后按照上面的建议正常打印F[][],