[英]Removing image noise like dots and lines
我是 OpenCV 和 Python 的新手,在去除输入图像中的噪声时遇到了问题。 我只想提取 WBC 的细胞核,所以我使用加法来突出显示细胞核,并使用阈值去除图像中的 RBC。 我成功去除了红细胞,但血小板没有去除,边界上出现了一些线条。 我还尝试使用膨胀、腐蚀、开闭来对图像进行去噪,但核被破坏了。
这是我的代码:
img = cv2.imread('1.bmp')
img_2 = cv2.imread('1.bmp')
input_img = cv2.addWeighted(img, 0.55, img_2, 0.6, 0)
retval, threshold = cv2.threshold(input_img, 158, 255, cv2.THRESH_BINARY)
threshold = cv2.cvtColor(threshold, cv2.COLOR_BGR2GRAY)
retval2, threshold2 = cv2.threshold(threshold, 0, 255,
cv2.THRESH_BINARY+cv2.THRESH_OTSU)
blur2 = cv2.medianBlur(threshold2,5)
这是原始图像:
阈值化后:
如果您突出显示的 WBC 的核心在阈值化之前始终是最大的轮廓,我建议使用findContours
单独存储它并删除较小的斑点,如下所示:
vector<vector<Point>>contours; //Vector for storing contour
vector<Vec4i> hierarchy;
//Find the contours in the image
findContours(input_img, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE);
for (int i = 0; i< contours.size(); i++) // iterate through each contour.
{
double a = contourArea(contours[i], false); // Find the area of contour
if (a>largest_area){
largest_area = a;
//Store the index of largest contour
largest_contour_index = i;
// Find the bounding rectangle for biggest contour
bounding_rect = boundingRect(contours[i]);
}
}
Scalar color(255, 255, 255);
// Draw the largest contour using the previously stored index.
Mat dst;
drawContours(dst, contours, largest_contour_index, color, CV_FILLED, 8, hierarchy);
我的代码是 C++,但您可以找到 python 示例: How to detection and draw contours using OpenCV in Python?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.