gpt4 book ai didi

java - java中的离散余弦变换(DCT)

转载 作者:太空宇宙 更新时间:2023-11-04 14:08:20 26 4
gpt4 key购买 nike

这是DCT源代码..!!!未知的 4x4 DCT 数组将通过将 4x4 数组分割成几个 block 来完成,每个 block 上经过 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 大小的 block 。因此,4x4 数组将由 4 个 2x2 部分组成,然后对每个部分进行变换,数组 F 将变为 f。然而,当显示数组f时,只出现红色条纹!可能有错误,所以请帮忙......! eksekusi

这是我想要的程序概述的示例: enter image description here

最佳答案

试试这个。对您的代码进行一些更改:

在主类中:

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

在 DCT 类中:

更改F[u][v] = sum;F[u+row][v+column] = sum;里面for循环。

关于java - java中的离散余弦变换(DCT),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28621011/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com