2DFFT-Ergebnis ist verrauscht

rainer82

Grünschnabel
Hi Leute,

ich bin schon des laengeren am tueffteln mit fftw, bekomme es aber einfach nicht auf die Reihe.

Moechte einfach die 2D fft ausfuehren. Finde einfach keinen Fehler in meinem Algorithmus. Deshalb mal eine Frage an die Experten. Koennt ihr mal bitte meinen Code ueberfliegen? Meine Bilder von der fft sind nur verrauscht wie ein Fernseher der kein Signal hat. Es sind aber allerdings senkrechte, dunkelgraue Streifen in regelmaessigen Abstaenden angeordnet, falls das hilft.

Hier der Code:
Code:
BYTE* CTransform::FFTForward(BYTE *dataIn)
{
	fftw_complex* in=0;
	fftw_complex* out=0;
	
	int N=width*height;

	in	=(fftw_complex*)fftw_malloc(N*sizeof(fftw_complex));
	out	=(fftw_complex*)fftw_malloc(N*sizeof(fftw_complex));

	int count	=0;
	int index	=0;
	int offset	=0;
	for (int j=0;j<512;j++)		// fill fftw_complex input data for fft
		{
			offset=j*width;
			for(int i=0;i<512;i++)
				{
					index=offset+i;
					in[index][0]=(dataIn[count++];	//real
					in[index][1]=0.0;				//imag
				}
		}
	fftw_plan plan=fftw_plan_dft_2d(512,512,in,out,FFTW_FORWARD,FFTW_ESTIMATE);
	fftw_execute(plan);			
	fftw_destroy_plan(plan);

	double*	temp;

	temp=new double[DATALENGTH];
	double	tempi;
	count = 0;
	for(int j=0;j<512;j++)
		{
			offset=j*width;
			for(int i=0; i<512; i++)
				{
					index=offset+i;
					tempi=sqrt((out[index][0]*out[index][0])+(out[index][1]*out[index][1]));
					if(tempi!=(double)0.0)	temp[count++]=log(tempi);
					else					temp[count++]=0.0;
				}
		}
	BYTE*	dataOut;

	dataOut=new BYTE[DATALENGTH];
	dataOut=Normalize(temp);

	return dataOut;
}

BYTE* CTransform::Normalize(double* data)
{
	double max, min;
	min=max=data[0];

	// find min, max amplitude
	for(int i=0;i<262143;i++)
		{
			if(data[i]>max) max=data[i];
			if(data[i]<min) min=data[i];
		}
	// normalize in range 0-255
	for(int i=0;i<262143;i++)
		{
			data[i]=(255.0*(data[i]-min))/(max-min);
		}
	return (BYTE*)data;
}

Meine Bilderstellungsroutine stimmt auf jeden Fall. Zur Sicherheit hier aber auch nochmal der Code:
Code:
bool CGetPrepareDataFiles::CreateBitmap(CString path,BYTE* data)
{
	BITMAPINFO			bi;
	HANDLE				fileHandle;
	BITMAPFILEHEADER	bmfh;
	BITMAPINFOHEADER	bmih;
	DWORD				bytes_write;
	DWORD				bytes_written;

	ZeroMemory(&bmih,sizeof(BITMAPINFOHEADER));
	bmih.biSize=sizeof(BITMAPINFOHEADER);
	bmih.biHeight=COLS;
	bmih.biWidth=ROWS;
	bmih.biPlanes=1;
	bmih.biBitCount=24;
	bmih.biCompression=BI_RGB;
	bmih.biSizeImage=((((bmih.biWidth*bmih.biBitCount)+31)& ~31) >> 3)*bmih.biHeight;
	bmih.biXPelsPerMeter=0;
	bmih.biYPelsPerMeter=0;
	bmih.biClrImportant=0;

	bi.bmiHeader=bmih;

	ZeroMemory(&bmfh,sizeof(BITMAPFILEHEADER));
	bmfh.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
	bmfh.bfSize=(3*bmih.biHeight*bmih.biWidth)+sizeof( BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
	bmfh.bfType=0x4d42;
	bmfh.bfReserved1 = 0;
	bmfh.bfReserved2 = 0;

	fileHandle=CreateFile(path,GENERIC_READ | GENERIC_WRITE,(DWORD)0,NULL,
	CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,(HANDLE) NULL);
	if (fileHandle==INVALID_HANDLE_VALUE) return false;
	// Write the BITMAPFILEHEADER
	bytes_write=sizeof(BITMAPFILEHEADER);
	if (!WriteFile(fileHandle,(void*)&bmfh,bytes_write,&bytes_written,NULL)) return false;
	//Write the BITMAPINFOHEADER
	bytes_write=sizeof(BITMAPINFOHEADER);
	if (!WriteFile(fileHandle,(void*)&bmih,bytes_write,&bytes_written,NULL)) return false;
	
	BYTE* dataRGB;

	dataRGB=new BYTE[ROWS*COLS*3];
	int j=0;

	for(int i=0;i<DATALENGTH;i++)
		{
			dataRGB[j++]=data[i];
			dataRGB[j++]=data[i];
			dataRGB[j++]=data[i];
		}
	//Write the Color Index Array
	bytes_write=bmih.biSizeImage;//3*bmih.biHeight*bmih.biWidth;
	if (!WriteFile(fileHandle,(void*)dataRGB,bytes_write,&bytes_written,NULL)) return false;
	delete[] dataRGB;
	CloseHandle(fileHandle);

	return true;
}

Vielen Dank schon mal vorab.

Gruss Rainer
 
Zurück