연구에 대하여
보다 나은 웹성능 향상을 위한 연구를 위해 머스트에서 오픈하는 커뮤니티 공간입니다.
Discrete Fourier Transform Program Coding
1. input image : created image with proper size
2. program code must be your own
3. Display
□ image -> DFT -> log scale transform -> Display
512×512 image
1024×1024 image
왼쪽: 원본 이미지
중간 : normal display of FFT transform
오른쪽 : log display of FFT transform
Code
public Bitmap ToBitmap(bool logTransform)
{
// create new image
Bitmap dstImage = YU.Imaging.Image.CreateGrayscaleImage(width, height);
// lock destination bitmap data
BitmapData dstData = dstImage.LockBits(
new Rectangle(0, 0, width, height),
ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
int offset = dstData.Stride - width;
double scale = (fourierTransformed) ? Math.Sqrt(width * height) : 1;
double minMagnitude = double.MaxValue;
double maxMagnitude = double.MinValue;
double minLog = double.MaxValue;
double maxLog = double.MinValue;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
minMagnitude = Math.Min(minMagnitude, data[y,x].Magnitude);
maxMagnitude = Math.Max(maxMagnitude, data[y,x].Magnitude);
minLog = Math.Min(minLog, Math.Log(data[y, x].Magnitude));
maxLog = Math.Max(maxLog, Math.Log(data[y, x].Magnitude));
}
}
// do the job
unsafe
{
byte* dst = (byte*)dstData.Scan0.ToPointer();
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++, dst++)
{
if (logTransform)
*dst = (byte)System.Math.Max(0, System.Math.Min(255, (Math.Log(data[y, x].Magnitude) - minLog) * 255 / (maxLog - minLog)));
else
*dst = (byte)System.Math.Max(0, System.Math.Min(255, data[y, x].Magnitude * scale * 255));
}
dst += offset;
}
}
// unlock destination images
dstImage.UnlockBits(dstData);
return dstImage;
}
관련문서 : http://lab.must.or.kr/Fourier-Transform-Properties.ashx