#include #include void fout( double [][8], int, int ); main(){ int i,j,k,l,p,q; double temp[8][8]; double alp_k = 1.0, alp_l = 1.0; int ada[8][8]={{ 1, 1, 1, 1, 1, 1, 1, 1},//0アダマール行列 {-1,-1,-1,-1, 1, 1, 1, 1},//1 {-1,-1, 1, 1, 1, 1,-1,-1},//2 { 1, 1,-1,-1, 1, 1,-1,-1},//3 { 1,-1,-1, 1, 1,-1,-1, 1},//4 {-1, 1, 1,-1, 1,-1,-1, 1},//5 {-1, 1,-1, 1, 1,-1, 1,-1},//6 { 1,-1, 1,-1, 1,-1, 1,-1}};//7 for( k = 0; k < 8; k++ ){ for( l = 0; l < 8; l++ ){ for( p = 0; p < 8; p++ ){ for( q = 0; q < 8; q++ ){ if(k==0) alp_k = 1 / ( sqrt(2.0) ); if(l==0) alp_l = 1 / ( sqrt(2.0) ); temp[p][q] = (2.0*alp_k*alp_l)*cos(M_PI*k*(2*p+1)/(2*8))*cos(M_PI*l*(2*q+1)/(2*8)) / 8.0; //temp[k][l] = ada[i][l] * ada[j][k]; // fout( temp, i, j ); // printf("%f ",temp); alp_k = alp_l = 1.0; } // printf("\n"); } fout( temp, k, l); // printf("\n"); } } } void fout( double temp[][8],int u, int v ){ FILE *fpout; char name[] = "out",kaku[]=".pgm"; char str[16]; int i,j; double max = 0.0; double min = 0.0; sprintf( str, "%s%d%d%s", name, u, v, kaku ); fpout = fopen( str, "w" ); for( i = 0; i < 8; i++ ){ for( j = 0; j < 8; j++ ){ // if( temp[i][j] <= 0 ){ temp[i][j] = 510.0 * temp[i][j] + 127.5; // } } } fprintf( fpout, "P2\n8 8\n255\n" ); for( i = 0; i < 8; i++ ){ for( j = 0; j < 8; j++ ){ fprintf( fpout, "%d ",(int)temp[i][j] ); if(max < temp[i][j]) max = temp[i][j]; if(min > temp[i][j]) min = temp[i][j]; } fprintf( fpout, "\n" ); } printf("max = %f , min = %f \n",max,min); fclose( fpout ); }