大家好,谢谢 我是一名学生,我正在为我的最终项目编写一个C++代码。 我的代码的问题是与边缘检测算法(图像处理), 而我在MATLAB我跑边缘检测算法取得了良好的边缘检测,但如果我正在用C语言编写的算法代码++,创建画面检测不良。边缘检测 - 检测不良
我尝试用0.03阈值检测与MATLB边缘和检测是伟大的(在我的项目的变化是非常低的(白色面变化不大)。
谢谢你这么多 伊詹。
也许有人可以帮助我,这是我的代码:
void ApplySobelFilter(unsigned char src[][NUMBER_OF_COLUMNS], float Threshold)
{
unsigned char dst[NUMBER_OF_ROWS][NUMBER_OF_COLUMNS];
unsigned char * ptrToImage;
ptrToImage = dst[0];
// Kernels for sobel operator
int Kernel_X[3][3] = { { -1, 0, 1 },{ -2, 0, 2 },{ -1, 0, 1 } };
int Kernel_Y[3][3] = { { 1, 2, 1 },{ 0, 0, 0 },{ -1, -2, -1 } };
// clears destination image
for (int pixel = 0; pixel < NUMBER_OF_ROWS*NUMBER_OF_COLUMNS; pixel++)
*ptrToImage++ = 0;
for (int row = 1; row < NUMBER_OF_ROWS - 1; row++)
for (int column = 1; column < NUMBER_OF_COLUMNS - 1; column++)
{
double Gtot = 0;
int Gx = 0;
int Gy = 0;
for (int x = -1; x <= 1; x++)
for (int y = -1; y <= 1; y++)
{
Gx += src[row + y][column + x] * Kernel_X[y + 1][x + 1];
Gy += src[row + y][column + x] * Kernel_Y[y + 1][x + 1];
}
Gtot = sqrt(double(Gx^2 + Gy^2));
if (Gtot >= Threshold)
dst[row][column] = 255;
else
dst[row][column] = 0;
}
for (int row = 0; row < NUMBER_OF_ROWS; row++)
{
for (int col = 0; col < NUMBER_OF_COLUMNS; col++)
{
src[row][col] = dst[row][col];
}
}
}
嗨伊丹,欢迎来到卡住溢出!你熟悉OpenCV库吗?它是一个具有图像处理能力的C++库。它还包含索贝尔功能。欲了解更多信息:http://opencv.org/ – drorco
你可以发布一些图像(预期和结果)?或者,至少可以链接到他们? –
另一件事是,你的图像是一个grayScale图像吗? –