title: Discrete cosine Transform (DCT) in java
body: <p>This is the sourcecode DCT .. !!! unknown array of 4x4 DCT will be done by splitting the 4x4 array into several blocks past yyang 2x2 transformation on each block ... !!! I want to ask, how to display an array that has been done, but with size 4x4 transformation, and not the size of 2x2 .. !!! because it is only as a condition 2x2 to be transformed, once transformed restored to its original array size 4x4. please help...!!!</p>
  
  <pre><code>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&lt;N;x++) 
      {
          for (int y=0;y&lt;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&lt;2;i++)
          {
            for (int j=0;j&lt;2;j++) 
            {
  
           try {
               System.out.print(F[i][j]+" ");
               } 
               catch (Exception e)
               {
                  System.out.println(e);
               }
  
           }
               System.out.println(" ");
          }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is for the sourcecode DCT</p>
  
  <pre><code>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&lt;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 &lt; (f.length); row += 2) {
      for (int column = 0; column &lt; f[0].length; column+=2) {
       for (int u=0;u&lt;N;u++) 
       {
          for (int v=0;v&lt;N;v++) 
           {
             double sum = 0.0;
             for (int i=0;i&lt;N;i++)
             {
               for (int j=0;j&lt;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;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>display if the source code above is executed.
  so this program as a 4x4 array F, then do DCT on F 4x4 4x4 array but by breaking into pieces the size of 2x2. so, 4x4 array will consist of 4 parts 2x2, then each part is done transformations and array F will be f. however, when displaying the array f, which appear only the red stripes !! there may be a mistake, so I please help...!
  <img src="https://i.stack.imgur.com/WEUQ3.png" alt="eksekusi"></p>
  
  <p>This is an example of an overview of the program that I want :
  <img src="https://i.stack.imgur.com/PlVAY.png" alt="enter image description here"></p>