see A.3.3 on page 27
JFIF Image class - Java
#46
Posted 27 August 2007 - 01:35 PM
see A.3.3 on page 27
#47
Posted 28 August 2007 - 07:05 AM
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.
#48
Posted 28 August 2007 - 07:47 AM
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.
#49
Posted 28 August 2007 - 01:30 PM
thanx, now just huffman to work out
Edited by staticVoid, 28 August 2007 - 01:30 PM.
#50
Posted 29 August 2007 - 09:26 AM
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.
#51
Posted 02 September 2007 - 08:53 AM
#52
Posted 02 September 2007 - 10:01 AM
but ...
there are bitwise operators and methods
http://www.particle....ter10/bits.html
http://java.sun.com/...dbolts/op3.html
#53
Posted 03 September 2007 - 10:44 AM
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.
#54
Posted 03 September 2007 - 12:25 PM
please let me know if this becomes resolved before you receive the next reply.
#55
Posted 03 September 2007 - 12:48 PM
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.
#56
Posted 03 September 2007 - 02:19 PM
#57
Posted 03 September 2007 - 03:52 PM
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.
#58
Posted 04 September 2007 - 01:21 AM
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.
#59
Posted 04 September 2007 - 04:13 AM
................................................................
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
#60
Posted 04 September 2007 - 05:53 AM
Similar Topics
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users