2007 August 07 17:22:58 BRT August 7, 2007
Posted by Girino Vey in : Uncategorized , trackbackimplementação da transformada discreta de cosseno em java
Mais uma busca que caia no meu site. Provavelmente por causa do artigo Transformada discreta de cosseno, e dos diversos artigos com código java. Para não deixar o público na mão, resolvi implementar :)
Quem quiser mais detalhes sobre o que é isso e pra que serve leiam o artigo:
public class dct { /** * Calcula a DCT (Transformada Discreta de Cosseno) de uma matriz * quadrada NxN. * Este código não é otimizado, para possíveis otimizações, * definições e detalhes, veja * http://www.girino.org/mediawiki/index.php/Transformada_discreta_de_cosseno * * @param img a matriz (imagem) a ser codificada. * @param size o tamanho da matriz. * @return a matriz transformada. **/ public static double[][] dct(double[][] img, int size) { double[][] ret = new double[size][size]; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { ret[i][j] = 0; for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) { double tmp = img[x][y]; tmp *= Math.cos((2*y + 1) * j * Math.PI/(2*size)); tmp *= Math.cos((2*x + 1) * i * Math.PI/(2*size)); ret[i][j] += tmp; } } ret[i][j] *= 1.0/Math.sqrt(2*size); ret[i][j] *= i==0?1.0/Math.sqrt(2):1.0; ret[i][j] *= j==0?1.0/Math.sqrt(2):1.0; } } return ret; } /** Matriz de exemplo usada no método main() **/ public static double[][] test = { {1. , 19. , 37. , 55. , 73. , 91. , 109. , 127.}, {19. , 37. , 55. , 73. , 91. , 109. , 127. , 145.}, {37. , 55. , 73. , 91. , 109. , 127. , 145. , 163.}, {55. , 73. , 91. , 109. , 127. , 145. , 163. , 181.}, {73. , 91. , 109. , 127. , 145. , 163. , 181. , 199.}, {91. , 109. , 127. , 145. , 163. , 181. , 199. , 217.}, {109. , 127. , 145. , 163. , 181. , 199. , 217. , 235.}, {127. , 145. , 163. , 181. , 199. , 217. , 235. , 253.} }; /** Exemplo. Executa o DCT na matriz de exemplo e imprime o resultado **/ public static void main(String[] args) { double[][] tmp = dct(test, 8); for (int i = 0; i < 8; i ++) { for (int j = 0; j < 8; j++) { System.out.print(tmp[i][j]); System.out.print(", "); } System.out.print("\n"); } } }
–GirinoVey 17:32, 7 Agosto 2007 (BRT)
![[linkk]](http://girino.org/wordpress/wp-content/plugins/bookmarkify/linkk.gif)
![[Linkto]](http://girino.org/wordpress/wp-content/plugins/bookmarkify/img_vote_16x16.jpg)
![[Rec6]](http://girino.org/wordpress/wp-content/plugins/bookmarkify/botao_rec6_16x16.gif)
![[InfoBlogs]](http://girino.org/wordpress/wp-content/plugins/bookmarkify/i.gif)
![[Uêba]](http://girino.org/wordpress/wp-content/plugins/bookmarkify/ueba1.png)
![[del.icio.us]](http://girino.org/wordpress/wp-content/plugins/bookmarkify/delicious.png)
![[Facebook]](http://girino.org/wordpress/wp-content/plugins/bookmarkify/facebook.png)
![[Google]](http://girino.org/wordpress/wp-content/plugins/bookmarkify/google.png)
![[Reddit]](http://girino.org/wordpress/wp-content/plugins/bookmarkify/reddit.png)
![[StumbleUpon]](http://girino.org/wordpress/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Technorati]](http://girino.org/wordpress/wp-content/plugins/bookmarkify/technorati.png)
![[Email]](http://girino.org/wordpress/wp-content/plugins/bookmarkify/email.png)

Comments»
no comments yet - be the first?