我不知道如何擬合曲線,如果在另一個問題中提出這個問題,你會很高興。
關於噪音:此功能應該做的伎倆,我用它來消除黑色和等待圖像中的噪音。 它是一本書一個代碼示例:
掌握的OpenCV與實用計算機視覺項目 - 丹尼爾Lelis 巴喬
我的這些包括在哪裏這個功能被實例化的頭說:
#include "opencv2/opencv.hpp"
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace cv;
using namespace std;
mask是你想要過濾的圖像,它可以去掉在分析過的任何5個像素中沒有點的點... 希望它有幫助s
void removePepperNoise(Mat &mask)
{
// For simplicity, ignore the top & bottom row border.
for (int y=2; y<mask.rows-2; y++) {
// Get access to each of the 5 rows near this pixel.
uchar *pThis = mask.ptr(y);
uchar *pUp1 = mask.ptr(y-1);
uchar *pUp2 = mask.ptr(y-2);
uchar *pDown1 = mask.ptr(y+1);
uchar *pDown2 = mask.ptr(y+2);
// For simplicity, ignore the left & right row border.
pThis += 2;
pUp1 += 2;
pUp2 += 2;
pDown1 += 2;
pDown2 += 2;
for (int x=2; x<mask.cols-2; x++) {
uchar v = *pThis; // Get the current pixel value (either 0 or 255).
// If the current pixel is black, but all the pixels on the 2-pixel-radius-border are white
// (ie: it is a small island of black pixels, surrounded by white), then delete that island.
if (v == 0) {
bool allAbove = *(pUp2 - 2) && *(pUp2 - 1) && *(pUp2) && *(pUp2 + 1) && *(pUp2 + 2);
bool allLeft = *(pUp1 - 2) && *(pThis - 2) && *(pDown1 - 2);
bool allBelow = *(pDown2 - 2) && *(pDown2 - 1) && *(pDown2) && *(pDown2 + 1) && *(pDown2 + 2);
bool allRight = *(pUp1 + 2) && *(pThis + 2) && *(pDown1 + 2);
bool surroundings = allAbove && allLeft && allBelow && allRight;
if (surroundings == true) {
// Fill the whole 5x5 block as white. Since we know the 5x5 borders
// are already white, just need to fill the 3x3 inner region.
*(pUp1 - 1) = 255;
*(pUp1 + 0) = 255;
*(pUp1 + 1) = 255;
*(pThis - 1) = 255;
*(pThis + 0) = 255;
*(pThis + 1) = 255;
*(pDown1 - 1) = 255;
*(pDown1 + 0) = 255;
*(pDown1 + 1) = 255;
}
// Since we just covered the whole 5x5 block with white, we know the next 2 pixels
// won't be black, so skip the next 2 pixels on the right.
pThis += 2;
pUp1 += 2;
pUp2 += 2;
pDown1 += 2;
pDown2 += 2;
}
// Move to the next pixel.
pThis++;
pUp1++;
pUp2++;
pDown1++;
pDown2++;
}
}
我認爲,擴張後更大的侵蝕應該在保持曲線的組成部分的同時去除大部分僞影。爲了適應曲線,你可以嘗試一些霍夫投票方法。 – ChronoTrigger
@ChronoTrigger不,更糟。被檢測的表面或者完全消失,具有比被認爲是噪聲的必要更多的像素。我正在尋找一種方法來保存檢測到的邊緣。也許類似於連接組件方法? – Eagle
@ChronoTrigger什麼是Hough投票計劃?你有幾個鏈接到我可以學習東西的文檔/實現? – Eagle