gpt4 book ai didi

python - 去除点和线等图像噪声

转载 作者:太空宇宙 更新时间:2023-11-03 22:41:23 25 4
gpt4 key购买 nike

我是 OpenCV 和 Python 的新手,在去除输入图像中的噪声时遇到了问题。我只想提取 WBC 的细胞核,所以我使用加法来突出显示细胞核,并使用阈值去除图像中的 RBC。我成功去除了红细胞,但血小板没有去除,边缘出现了一些线条。我还尝试使用膨胀、腐 eclipse 、打开和关闭来对图像进行去噪,但核被破坏了。

这是我的代码:

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)

这是原图:

enter image description here

阈值化后:

enter image description here

最佳答案

如果您突出显示的 WBC 细胞核在阈值化之前始终是最大的轮廓,我建议使用 findContours 单独存储它并像这样删除较小的 Blob :

 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 detect and draw contours using OpenCV in Python?

关于python - 去除点和线等图像噪声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53076271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com