Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 消除点和线等图像噪声_Python_Opencv - Fatal编程技术网

Python 消除点和线等图像噪声

Python 消除点和线等图像噪声,python,opencv,Python,Opencv,我刚接触OpenCV和Python,在去除输入图像中的噪声时遇到了一个问题。我只想提取白细胞的细胞核,所以我使用加法来突出显示细胞核,并使用阈值来去除图像中的红细胞。我成功地移除了红细胞,但血小板没有被移除,边界上出现了一些线条。我还试着用膨胀、腐蚀、打开和关闭来去除图像中的噪声,但是细胞核被破坏了 这是我的密码: img = cv2.imread('1.bmp') img_2 = cv2.imread('1.bmp') input_img = cv2.addWeighted(img, 0.55

我刚接触OpenCV和Python,在去除输入图像中的噪声时遇到了一个问题。我只想提取白细胞的细胞核,所以我使用加法来突出显示细胞核,并使用阈值来去除图像中的红细胞。我成功地移除了红细胞,但血小板没有被移除,边界上出现了一些线条。我还试着用膨胀、腐蚀、打开和关闭来去除图像中的噪声,但是细胞核被破坏了

这是我的密码:

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)
以下是原始图像:

阈值化后:


如果您突出显示的白细胞的细胞核在阈值设置之前始终是最大的轮廓,我建议使用
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); 
矢量轮廓//轮廓存储向量
向量层次;
//找到图像中的轮廓
findContours(输入图像、轮廓、层次、CV\u RETR\u CCOMP、CV\u CHAIN\u近似值\u SIMPLE);
对于(int i=0;i最大面积){
最大面积=a;
//存储最大轮廓的索引
最大等高线指数=i;
//找到最大轮廓的边框
bounding_rect=boundingRect(等高线[i]);
} 
}
标量颜色(255、255、255);
//使用先前存储的索引绘制最大轮廓。
Mat-dst;
绘制等高线(dst、等高线、最大等高线索引、颜色、CV填充、8、层次);

<>我的代码是C++,但是你可以找到Python例子:

你可能会发现SkVIEW中可用的形态学操作(关闭、打开)很有用。要提取红色区域吗?尝试HSV颜色空间并识别红色。嘿,伙计,谢谢你的建议,但我如何在一张图像中绘制多个细胞核?我知道如何绘制具有最大面积的一个,但如果有多个WBC,我该如何绘制?在这种情况下,您将希望现在有一个大小阈值限制,例如双大面积=100;因此,如果(a