C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[47519] 퓨리에 트랜스폼 이거 실행 시키면 자꾸 화면이 백색이 되네여..
예비졸업생 [] 1099 읽음    2006-12-22 11:42
어디가 문제인지좀 설명해주세요...
자꾸만 해도 이러니 답답하네여..

void __fastcall TForm1::fft1Click(TObject *Sender)
{

     int i,j,ic;
       
        ClientHeight=maxy;
        ClientWidth=maxx;
        //pB= new Graphics::TBitmap();
        //pB->Height=maxy;
       // pB->Width=maxx;


        twoD_FFT();


        for(i=0;i<maxy;i++)
        {
         for(j=0;j<maxx;j++)
         {

         // pB->Canvas->Pixels[j][i]=RGB(ic,ic,ic);
          Image1->Canvas->Pixels[j][i]=RGB(ic,ic,ic);

         }
        }

}

void twoD_FFT()
{
      int x,y;
      int maxx,maxy;
      int index=0,i=0,j=0,k=0;

      COMPLEX complex_data[256*256];
      unsigned char m_OpenImg[256][256];
      unsigned char m_ResultImg[256][256];
      unsigned char m_ImageBuffer1[256][256];
      unsigned char m_ImageBuffer2[256][256];

//      unsigned int m;

     COMPLEX col_data[256];
     COMPLEX row_data[256];


    for(i=0; i<256; i++ )
        {
        col_data[i].re=0;
        col_data[i].im=0;
        row_data[i].re=0;
        row_data[i].im=0;
        for(j=0; j<256; j++)
                {
            complex_data[k+j].re=m_OpenImg[i][j];
            complex_data[k+j].im=0;
        }
        k+=256;
    }
    k=0;

    for(int y=0; y<256; y++)
        {
        index=y*256;
        for(int x=0; x<256; x++)
        {
            row_data[x].re = complex_data[index].re;
            row_data[x].im = complex_data[index++].im;
        }
        fft(row_data,8,256,1);

        index=y*256;
        for(x=0; x<256; x++)
        {
            complex_data[index].re = row_data[x].re;
            complex_data[index++].im = row_data[x].im;
        }
    }

    for(int x=0; x<256; x++)
        {
        index=x;
        for(int y=0; y<256; y++)
        {
            col_data[y].re = complex_data[index].re;
            col_data[y].im = complex_data[index].im;
            index += 256;
        }
        fft(col_data,8,256,1);

        index=x;
        for(y=0; y<256; y++)
        {
            complex_data[index].re = col_data[y].re;
            complex_data[index].im = col_data[y].im;
            index += 256;
        }
    }

    //result
    for(i=0; i<256; i++)
        {
       for(j=0; j<256; j++)
           {
         m_ResultImg[i][j]=20*log(1+abs(complex_data[k+j].re));
         if(m_ResultImg[i][j]>=170)m_ResultImg[i][j]=255;
         else m_ResultImg[i][j]=0;
       }
        k+=256;
    }
    fftview();
}
//---------------------------------------------------------------------------

void fft(COMPLEX *f, int logN, int numpoints, int dir)
{
    scramble(numpoints,f);
    butterflies(numpoints,logN,dir,f);
}

void scramble(int numpoints, COMPLEX *f)
{
    int i,j,m;    //loop variable
    double temp;    //temporary storage during swapping

    j=0;
    for(i=0;i<numpoints;i++)    //numpoint배열의 element 수
    {
        if(i>j)
        {
            //swap real
            temp=f[j].re;
            f[j].re=f[i].re;
            f[i].re=(float)temp;
            //swap imagenary
            temp=f[j].im;
            f[j].im=f[i].im;
            f[i].im=(float)temp;
        }
        m=numpoints>>1;
        while(( j >= m ) & ( m >= 2 ))
        {
            j -=m;
            m = m >> 1;
        }
        j +=m;
    }
}

void butterflies(int numpoints, int logN, int dir, COMPLEX *f)
{
    double angle;        //polar angle
    COMPLEX w,wp,temp;    //intermediate complex numbers
    int i,j,k,offset;    //loop variables
    int N,half_N;        //storage for powers of 2
    double wtemp;        //temporary storage for w.re

    N=1;
    for(k=0; k<logN; k++)
    {
        half_N=N;
        N <<= 1;
        angle = -2.0 * PI / N * dir;
        wtemp = sin(0.5*angle);
        //wp.re = (float)sin(0.5*angle);//변경.
        wp.re = (float)(-2.0*wtemp*wtemp);

        wp.im = (float)sin(angle);//변경
        w.re = 1.0;
        w.im = 0.0;
        for(offset=0; offset<half_N; offset++)
        {
            for(i=offset; i<numpoints; i+=N)
            {
                j=i+half_N;
                temp.re = (w.re*f[j].re)-(w.im*f[j].im);
                temp.im = (w.im*f[j].re)+(w.re*f[j].im);
                f[j].re = f[i].re-temp.re;
                f[i].re += temp.re;
                f[j].im = f[i].im-temp.im;
                f[i].im += temp.im;
            }
            wtemp = w.re;
            w.re = (float)(wtemp*wp.re-w.im*wp.im+w.re);//변경.
            w.im = (float)(w.im*wp.re+wtemp*wp.im+w.im);//변경.
        }
    }
    if(dir == -1)
        for(i=0;i<numpoints;i++)
        {
            f[i].re /= numpoints;
            f[i].im /= numpoints;
        }
}

void fftview()
{
        unsigned char fftview[256][256];
        unsigned char m_ResultImg[256][256];
    //convert
    for(int i=0; i<256; i+=128){
        for(int j=0; j<256; j+=128){
            for(int row=0; row<128; row++){
                for(int col=0; col<128; col++){
                    fftview[127-row+i][127-col+j]=m_ResultImg[i+row][j+col];
                }
            }
        }
    }

    for(int y=0; y<256; y++){
        for(int x=0; x<256; x++){
            m_ResultImg[y][x]=fftview[y][x];
        }
    }
}



//---------------------------------------------------------------------------

아는 분들 뭐가 문제인지 답변 부탁 드립니다.

+ -

관련 글 리스트
47519 퓨리에 트랜스폼 이거 실행 시키면 자꾸 화면이 백색이 되네여.. 예비졸업생 1099 2006/12/22
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.