大家好,謝謝 我是一名學生,我正在爲我的最終項目編寫一個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圖像嗎? –