我正在尝试实现本文所述的 Gabor Wavelet 功能: “用于浏览和检索图像数据的纹理特征”
特征向量由均值和标准差组成(下面的特征向量示例比例=4,方向=6)
实现代码:
void gabor_main(int argc, char **argv)
{
int img_height; // height of input image
int img_width; // width of input image
int side; // side (filter dimension = (2*side+1)*(2*side+1)) = 60
int scale; // number of scale
int orientation; // number of orientation
int flag; // flag (removing the DC term) = 0 (False)
FILE* fp;
unsigned char *tmp_raw_img; // temporary raw image data
double Ul; // Uh (highest spatial frequency)
double Uh; // Ul (lowest spatial frequency)
Matrix* img_mat; // input image
Matrix* F_r; // result, real part
Matrix* F_i; // result, imaginary part
Matrix* F_m; // result, magnitude of real part and imaginary part
scale = 4;
orientation = 6;
Ul = 0.1;
Uh = 0.4;
flag = 0;
side = 60;
...
/* ----------------- Reading raw image ----------------- */
...
/* ----------------- Gabor filtered outputs ----------------- */
CreateMatrix(&F_r, img_height * scale, img_width * orientation); // memory allocation of real part matrix of the output
CreateMatrix(&F_i, img_height * scale, img_width * orientation); // memory allocation of imaginary part matrix of the output
CreateMatrix(&F_m, img_height * scale, img_width * orientation); // // memory allocation of magnitude of the output
GaborFilteredImg(F_r, F_i, img_mat, side, Ul, Uh, scale, orientation, flag);
/* ----------------- Compute Feature Vector ----------------- */
// Magnitude of complex value
for (int h = 0; h < (img_height * scale); h++)
{
for (int w = 0; w < (img_width * orientation); w++)
{
F_m->data[h][w] = sqrt(F_r->data[h][w] * F_r->data[h][w] + F_i->data[h][w] * F_i->data[h][w]);
}
}
for(int i = 0; i < scale; i++)
{
for(int j = 0;j < orientation; j++)
{
double avg = Average(F_m, img_height, img_width, i, j);
double std = StandardDeviation(F_m, img_height, img_width, i, j);
// Print the result
std::cout << avg << " " << std << "\n";
}
}
FreeMatrix(F_r);
FreeMatrix(F_i);
FreeMatrix(F_m);
}
均值和标准差代码:
double Average(Matrix* F_m, int img_height, int img_width, int scale, int orientation)
{
double avg = 0.0;
for (int h = (img_height * scale); h < (img_height * (scale + 1)); h++)
{
for (int w = (img_width * orientation); w < (img_width * (orientation + 1)); w++)
{
avg += F_m->data[h][w];
}
}
avg /= (img_height * img_width);
return avg;
}
double StandardDeviation(Matrix* F_m, int img_height, int img_width, int scale, int orientation)
{
double std = 0.0;
double avg = Average(F_m, img_height, img_width, scale, orientation);
for (int h = (img_height * scale); h < (img_height * (scale + 1)); h++)
{
for (int w = (img_width * orientation); w < (img_width * (orientation + 1)); w++)
{
double dif = F_m->data[h][w] - avg;
std += (dif * dif);
}
}
std = sqrt(std / (img_height * img_width));
return std;
}
注意:我从这个http://vision.ece.ucsb.edu/texture/software/gabor.c复制的 GaborFilteredImg 的功能代码
我想问一下我写的代码(从“计算纹理特征”部分开始)是否正确。我不确定在给定输出 F_r(实部)和 F_i(虚部)的情况下获得均值和标准值。基本上我计算gabor滤波器组的每个响应的平均值和标准差
===更新===
那些 F_r 和 F_i 是使用 scale=4 和orientation=6 的gabor 滤波的结果。F_r 和 F_i 都有维度 (img_height * scale) * (img_width *orientation) 基本上由 gabor 滤波器组的每个响应的网格组成。
然后我计算幅度 F_m(x,y) = sqrt(F_r(x, y) * F_r(x, y) + F_i(x, y) * F_i(x, y))
最后我计算了特征向量,它是 F_m 的均值和标准差
===图片===
图片输入(真实):http: //goo.gl/kc5BG
Gabor 银行(真实):http: //goo.gl/0qM4E
Gabor 银行(虚构):http: //goo.gl/r7Fnk
输出(真实):http: //goo.gl/nxVMn
输出(虚构):http: //goo.gl/SnD7p