资源简介
Perona和Malik在热传导方程的基础上,建立了各向异性扩散方程并将其应用到了图像处理中尺度空间的图像平滑上,该模型针对图像的边缘部分和非边缘部分进行不同性质的图像处理,同时解算方程的迭代格式简单,克服传统滤波的主要缺陷,是图像质量大为改善,为图像的边缘检测和增强开辟了新的方向。
代码片段和文件信息
#include “anisodiff2D.h“
static void ani2D_init()
{
int i = 0j;
struct CFFT32 fft2_inst;
if(ani2D_const_init)return;//initiate only if first called
ani2D_const_init = 1;
//allocate memory
ani2D_h = calloc(8*2*256*256 sizeof(double));
if(!ani2D_h)
{
printf(“allocate memory failed\r\n“);
return;
}
// initiate eight direction filter constants
for (i=0;i<8;i++)
{
// 3*3 dx=dy=1
if(i>3)j=i+1;
else j=i;
ani2D_h[ANI2D_H(i011)] = -1;
ani2D_h[ANI2D_H(i0j/3j%3)] = 1;
//2D FFT
CFFT32_init(&fft2_inst &ani2D_h[ANI2D_H(i000)] &ani2D_h[ANI2D_H(i100)] (double *)&ani2D_bfR (double *)&ani2D_bfI 256);
CFFT2_calc(&fft2_inst);
}
}
void ani2D_free()
{
if(!ani2D_const_init)return;
ani2D_const_init = 0;
free(ani2D_h);
ani2D_h = NULL;
}
#define DELTA_T 1.0/7.0
int anisodiff2D(BMP256 *imgin BMP256 *imgout int num_iter double kappa int option)
{
//local variables declaration
double *tmp;// tmp[0] - real part size:256*256; tmp[1] - imaginary part size:256*256; used for 2D-FFT
double *diff_im;// [0] - real part size:256*256; [1] - imaginary part size:256*256;
double *tmp_out;// used for save the output in double
double nablaX cX;
int ijkldd;
struct CFFT32 fft2_inst;
//initiate loacal vrariables
ani2D_init();
tmp = calloc(2*256*256 sizeof(double));//complex matrix
diff_im = calloc(2*256*256 sizeof(double));//complex matrix
tmp_out = calloc(254*256 sizeof(double));//real matirx
if((!tmp)||(!diff_im)||(!tmp_out))
{
printf(“allocate memory failed\r\n“);
return -1;
}
CFFT32_init(&fft2_inst &tmp[0] &tmp[256*256] (double *)&ani2D_bfR (double *)&ani2D_bfI 256);
// preprocess the input and output
imgout->pHeight = 254;
imgout->pWidth = 254; // real image width
imgout->fWidth = 256; // real data width
imgout->pSize = imgout->fWidth * imgout->pHeight;
imgout->pData = calloc(imgout->pSize 1);
if(!imgout->pData)
{
printf(“allocate memory failed\r\n“);
return -1;
}
// only process the top-left-corner 254*254
if(imgin->pWidth >254)
i = 254;
else
i = imgin->pWidth;
if(imgin->pHeight >254)
j = 254;
else
j = imgin->pHeight;
for(k=0; k for(l=0; l tmp_out[k*256+l] = (double) imgin->pData[k*imgin->fWidth+l];
// iteration
for (i=0;i {
// copy from tmp_out to the real part of tmp
memset(tmp 0 2*256*256*sizeof(double));
memcpy(tmp tmp_out 254*256*sizeof(double));
CFFT2_calc(&fft2_inst);
// save a copy in diff_im fft2D(tmp_out)
memcpy(diff_im tmp 2*256*256*sizeof(double));
// filter in eight directions one direction a time
for(j=0; j<8; j++)
{
memcpy(tmp diff_im 2*256*256*sizeof(double));
// fft2D(img) .* fft2D(fileterX)
CMatrix_DotProduct(tmp &ani2D_h[ANI2D_H(i000)] 256);
// ifft2D
CFFT2_icalc(&fft2_inst);// only real part now
// P-M update tmp_out
fo
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3962 2011-07-04 21:28 src\anisodiff2D.c
文件 852 2011-07-04 21:28 src\anisodiff2D.h
文件 2041 2011-07-04 21:28 src\ImageFormat.c
文件 2385 2011-07-04 21:28 src\ImageFormat.h
文件 12662 2011-07-04 21:28 src\PeronaMalikmain.c
文件 2908 2010-07-27 16:36 src\T_fft.c
文件 6004 2011-07-04 21:28 src\T_fft.h
文件 2810 2010-07-27 20:41 src\T_fft2.c
文件 628 2011-07-04 21:28 src\T_fft2.h
目录 0 2011-07-04 21:28 src
----------- --------- ---------- ----- ----
34252 10
评论
共有 条评论