Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

JFIF Image class - Java


  • Please log in to reply

#46
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
take a look at the formula(s) in the 10918-1 spec for DCT & IDCT.

see A.3.3 on page 27
  • 0

Advertisements


#47
staticVoid

staticVoid

    Member

  • Topic Starter
  • Member
  • PipPip
  • 94 posts
I changed the equation but it produced the same values?

public class CosineTransformation {

   public CosineTransformation() {
   }

   public double[][] F = new double[8][8];
   public double Temp = 0.0;
   public double c = 0.0;

   public double[][] DCT(double[][] f) {
	  for(int u = 0; u < 8; u++) {
		 for(int v = 0; v < 8; v++) {
			if(v == 0 && u == 0) {
			   c = 0.5;
			} else {
			   c = 1.0; 
			}

			for(int x = 0; x < 8; x++) {
			   for(int y = 0; y < 8; y++) {
				  Temp += f[x][y] * Math.acos( (((2*x)+1) * u * Math.PI) / 16 )
								  * Math.acos( (((2*y)+1) * v * Math.PI) / 16 );
			   }
			}
			F[u][v] =  (c/4.0) * Temp;
			Temp = 0.0;
		 }
	  }
	  return F;
   }

   public void IDCT(double[][] f) {
   }

}

that follows the equation in the spec(I think)
any Ideas why its not working?

Edited by staticVoid, 28 August 2007 - 07:10 AM.

  • 0

#48
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
1. use cos() ... not acos()

2. / 16 ... is int division
try ... / 16.0

3. f[x][y]
try ... f[y][x]

4. F[u][v]
try ... F[v][u]

...........................................
not sure about this one

5. u == 0 && v == 0
might be u == 0 || v == 0

Edited by bdlt, 28 August 2007 - 08:00 AM.

  • 0

#49
staticVoid

staticVoid

    Member

  • Topic Starter
  • Member
  • PipPip
  • 94 posts
hey, It worked!
thanx, now just huffman to work out

Edited by staticVoid, 28 August 2007 - 01:30 PM.

  • 0

#50
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
congrats!

the tutorial below decodes a simple 2 block image. all of the AC values are 0.
it covers the basic steps for decoding huffman.

http://www.impulsead...man-coding.html

the most useful part is from the top up to 'conversion to spatial domain'(about half way through the page)

note - the example uses custom huffman tables(not K3-K6 of the spec)

Edited by bdlt, 29 August 2007 - 03:27 PM.

  • 0

#51
staticVoid

staticVoid

    Member

  • Topic Starter
  • Member
  • PipPip
  • 94 posts
is there a method in java for reading bits from a file?
  • 0

#52
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
sorry, I'm not aware of any methods that read bits from a file

but ...

there are bitwise operators and methods

http://www.particle....ter10/bits.html

http://java.sun.com/...dbolts/op3.html
  • 0

#53
staticVoid

staticVoid

    Member

  • Topic Starter
  • Member
  • PipPip
  • 94 posts
I'm not sure if this FDCT is giving the right results

public class CosineTransformation {

   public CosineTransformation() {
   }

   public double[][] F = new double[8][8];
   public double Temp = 0;
   public double c = 0;

   public double[][] DCT(float[][] f) {
	  for(int u = 0; u < 8; u++) {
		 for(int v = 0; v < 8; v++) {
			if(v == 0 && u == 0) {
			   c = 0.5;
			} else {
			   c = 1.0;
			}
			for(int x = 0; x < 8; x++) {
			   for(int y = 0; y < 8; y++) {
				  Temp += f[y][x] * Math.cos( (((2*x)+1) * u * Math.PI) / 16.0 )
								  * Math.cos( (((2*y)+1) * v * Math.PI) / 16.0 );
			   }
			}
			F[v][u] =  (c/4.0) * Temp;
			Temp = 0.0;
		 }
	  }
	  return F;
   }

   public void IDCT(int channel) {
   }

}

could you test it and see if its working?

Heres the the table from http://en.wikipedia.org/wiki/JPEG:

public float[][] TestArrayTwo = 

   {  {-76, -73, -67, -62, -58, -67, -64, -55},
	  {-65, -69, -73, -38, -19, -43, -59, -56},
	  {-66, -69, -60, -15, 16, -24, -62, -55 },
	  {-65, -70, -57, -6, 26, -22, -58, -59  },
	  {-61, -67, -60, -24, -2, -40, -60, -58 },
	  {-49, -63, -68, -58, -51, -60, -70, -53},
	  {-43, -57, -64, -69, -73, -67, -63, -45},
	  {-41, -49, -59, -60, -63, -52, -50, -34}  };

I put the array into the FDCT but the values didnt match the ones in wikipedia.?
I know theres probaly a few errors in the code.

Edited by staticVoid, 03 September 2007 - 10:50 AM.

  • 0

#54
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
evaluation of the code may involve some 'hand' calculations.

please let me know if this becomes resolved before you receive the next reply.
  • 0

#55
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
try this:

replace this
if(v == 0 && u == 0) {
c = 0.5;
} else {
c = 1.0;
}

with:

c = 1.0;
if( u == 0 ) {
c *= Math.sqrt(2.0) / 2.0;
}
if( v == 0 ) {
c *= Math.sqrt(2.0) / 2.0;
}

Edited by bdlt, 03 September 2007 - 12:52 PM.

  • 0

Advertisements


#56
staticVoid

staticVoid

    Member

  • Topic Starter
  • Member
  • PipPip
  • 94 posts
It's still not the right values , I'm getting the equation from http://www.opennet.r...ormats/jpeg.txt (I think it's right)
  • 0

#57
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
look at Temp for u = 0, v = 0

Temp = -3323
c = 0.5

F[0][0] = c * temp / 4.0 = (0.5 * -3323) / 4.0 = -415.375
..............................................................................
other Temp values
(V,U)
0,1 -170.76
0,2 -346.18
0,3 154.08
0,4 317.50
0,5 -113.68
0,6 -13.504
0,7 2.61

1.0 25.26
2,0 -264.93

..........................................................................

please post your current DCT code

Edited by bdlt, 03 September 2007 - 07:09 PM.

  • 0

#58
staticVoid

staticVoid

    Member

  • Topic Starter
  • Member
  • PipPip
  • 94 posts
I'm getting the values you listed in the right order but for example:

F(0, 1) = -170.76 * ( (c=1) /4 ) = -42.675

when (according to wikipedia) it should be -30 ??

Heres my DCT code:

public double[][] DCT(double[][] f) {
	  for(int u = 0; u < 8; u++) {
		 for(int v = 0; v < 8; v++) {
			if(v == 0 && u == 0) {
			   c = 0.5;
			} else {
			   c = 1.0; 
			}
			for(int x = 0; x < 8; x++) {
			   for(int y = 0; y < 8; y++) {
				  Temp += f[y][x] * Math.cos( (((2*x)+1) * u * Math.PI) / 16.0 )
								  * Math.cos( (((2*y)+1) * v * Math.PI) / 16.0 );
			   }
			}
			F[v][u] =  (c/4.0) * Temp;
			Temp = 0.0;
		 }
	  }
	  return F;
   }


I've also realized the values I'm getting are really close to (if not the same as) the table on wikipedia for a lot of the values but some are just way off

Edited by staticVoid, 04 September 2007 - 01:32 AM.

  • 0

#59
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
humor me ... please retry the suggestion in post #55

................................................................

the value for 'c' is a little confusing

avoid using jpeg.txt for DCT

wik and the spec agree on the DCT 'formula'

if we look at the spec(A.3.3 on p27) we see:
Cu, Cv = 1 / sqrt(2) for u,v = 0
otherwise Cu, Cv = 1

the suggestion in post #55 uses sqrt(2) / 2 which is the same as 1/sqrt(2)
sorry ... that probably adds to the confusion

.............................................................

'c' in your code is actually Cu * Cv

we have 4 different sets of Cu and Cv

1. u = 0 and v = 0(the DC value)
c = Cu * Cv = 1/ sqrt(2) * 1/sqrt(2) = 0.5
2. u = 0 and v != 0
c = 1/sqrt(2) * 1 = 1/sqrt(2) = 0.707
3 . u != 0 and v = 0
c = 1 * 1/sqrt(2) = 1/sqrt(2) = 0.707
4. u!= 0 and v!= 0
c = 1 * 1 = 1.0
  • 0

#60
staticVoid

staticVoid

    Member

  • Topic Starter
  • Member
  • PipPip
  • 94 posts
It worked - the reason it never worked last time was because I had display: F[y][x] instead of F[x][y] so it was right all along just not in the right order when I was displaying it.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP