Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.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 OpenCV:消除背景噪声并增加信号强度_Python_Opencv_Image Processing - Fatal编程技术网

Python OpenCV:消除背景噪声并增加信号强度

Python OpenCV:消除背景噪声并增加信号强度,python,opencv,image-processing,Python,Opencv,Image Processing,我是OpenCV新手,尝试了多种方法,但仍然存在一些问题。 我有这样的图像: 在中心有一个簇(很难看到)。我想找到这些簇并计算它们。我使用了cv2.findContours,这对于集群亮度好、背景噪声不太强的图像来说已经非常有效了 对于这样的图像,如果簇非常暗,或者背景噪声非常强,看起来与实际簇非常相似的图像,我在检测它们时会遇到问题 所以我现在要做的是去除背景噪声,这样就只剩下集群了。然后我可以增加图像的亮度,(我认为)应该更容易识别那些簇 背景噪音非常大!上面的图像是一个示例,其中没有太多

我是OpenCV新手,尝试了多种方法,但仍然存在一些问题。 我有这样的图像:

在中心有一个簇(很难看到)。我想找到这些簇并计算它们。我使用了
cv2.findContours
,这对于集群亮度好、背景噪声不太强的图像来说已经非常有效了

对于这样的图像,如果簇非常暗,或者背景噪声非常强,看起来与实际簇非常相似的图像,我在检测它们时会遇到问题

所以我现在要做的是去除背景噪声,这样就只剩下集群了。然后我可以增加图像的亮度,(我认为)应该更容易识别那些簇

背景噪音非常大!上面的图像是一个示例,其中没有太多的背景噪声,但可能更糟。 我有我知道的图像,其中没有簇(阴性对照)。那里的一切都是背景噪音。所以我的想法是在阴性对照中找到主色:

from skimage import io
def getDominantColor(image):
        a = io.imread(image)[:, :, :-1]
    
        colors, count = np.unique(a.reshape(-1, a.shape[-1]), axis=0, return_counts=True)
        return colors[count.argmax()]
主色应该是背景噪声。 然后从包含簇的图像中减去主色:

def substract(image, dominant):
    cells = cv2.imread(image)
    cells = cells[:, :, 2]
    cells = cv2.subtract(cells, dominant)
但此代码不起作用…:)但除此之外,我想知道你们是否认为这是解决这类问题的正确方向

简而言之,我想去除背景噪声,这样只有我感兴趣的信息才会留在图像中。 背景噪音可能很大,我有一些图像,我知道只有背景噪音在那里,没有其他东西

非常感谢你给我的任何提示! 顺致敬意,
Martin

在Python/OpenCV/Skimage中有一种方法

 - Read the input
 - Stretch to full dynamic range
 - Apply morphology to clean the image
 - Convert to gray
 - Otsu threshold
 - Get the largest contour
 - Draw the contour outline on the stretched image
 - Extract the contour region from the stretched image and place it on a black background
 - Save the results

输入:


拉伸到全动态范围图像:

形态学清理图像:

灰色图像:

阈值图像:

拉伸图像上的轮廓:

黑色背景上拉伸图像的轮廓区域:


在Python/OpenCV/Skimage中有一种方法

 - Read the input
 - Stretch to full dynamic range
 - Apply morphology to clean the image
 - Convert to gray
 - Otsu threshold
 - Get the largest contour
 - Draw the contour outline on the stretched image
 - Extract the contour region from the stretched image and place it on a black background
 - Save the results

输入:


拉伸到全动态范围图像:

形态学清理图像:

灰色图像:

阈值图像:

拉伸图像上的轮廓:

黑色背景上拉伸图像的轮廓区域:


这里是我以前在Python/OpenCV中的解决方案的另一个变体

 - Read the input
 - Stretch to full dynamic range
 - Convert to gray
 - Threshold
 - Blur
 - Threshold again
 - Get the largest contour
 - Draw the contour outline on the stretched image
 - Extract the contour region from the stretched image and place it on a black background
 - Save the results

输入:

  • 读取输入
  • 拉伸至全动态范围
  • 应用形态学来清理图像
  • 变灰
  • 大津阈值
  • 获得最大的轮廓
  • 在拉伸图像上绘制轮廓轮廓
  • 从拉伸图像中提取轮廓区域并将其放置在黑色背景上
  • 保存结果

拉伸图像:

灰色图像:

最终阈值图像:

结果1:

结果2:


这里是我以前在Python/OpenCV中的解决方案的另一个变体

 - Read the input
 - Stretch to full dynamic range
 - Convert to gray
 - Threshold
 - Blur
 - Threshold again
 - Get the largest contour
 - Draw the contour outline on the stretched image
 - Extract the contour region from the stretched image and place it on a black background
 - Save the results

输入:

  • 读取输入
  • 拉伸至全动态范围
  • 应用形态学来清理图像
  • 变灰
  • 大津阈值
  • 获得最大的轮廓
  • 在拉伸图像上绘制轮廓轮廓
  • 从拉伸图像中提取轮廓区域并将其放置在黑色背景上
  • 保存结果

拉伸图像:

灰色图像:

最终阈值图像:

结果1:

结果2:


谢谢!这看起来很有趣。我只是尝试一下,但我得到了以下错误:gray=cv2.cvtColor(morph,cv2.COLOR\u BGR2GRAY)…>不支持的输入图像深度:>'VDepth::contains(depth)>,其中>'depth'为6(CV_64F)。您可能知道问题出在哪里?我也试过彩色照片,同样的错误可能是OpenCV版本的问题。它适用于我的OpenCV 3.8和Python 3.7。您使用的是什么版本?输入图像的数据类型是什么<代码>打印(img.dtype)。作为猜测,请尝试
cv2.cvtColor(morph.astype(np.uint8)、cv2.COLOR\u bgr2 gray)
或enCV版本问题。它适用于我的OpenCV 3.8和Python 3.7。请尝试
cv2.cvtColor((255*morph).aType(np.uint8),cv2.COLOR\u bgr2 gray)
+1。你能解释一下形态学部分吗?我最近也在做类似的事情,除了有点原始的模糊,我想不出别的东西。我的意思是为什么你选择做你所做的,等等。形态闭合将更好地合并你的中心绿色,而开放将删除小的浅绿色圆点。如果在关闭后放置imshow,可以看到效果。对于去除小对象,形态学通常比模糊更有效。收盘是扩张,然后是侵蚀。开放是一个先侵蚀后扩张的过程。@fmw42我现在玩了一点(你对修复的建议起了作用),但这真的需要很长时间。以上只是一个示例图像。原始的是9000x9000像素。计算需要几分钟。。。这对我的用例来说太长了。你有没有别的想法?你认为使用直方图,找出最主要的颜色,然后去掉这个颜色怎么样。然后我会增加剩余颜色的强度。也许这不会像你的方法那样精确,但我的情况下也不需要100%的正确性。谢谢!这看起来很有趣。我只是尝试一下,但我得到了以下错误:gray=cv2.cvtColor(morph,cv2.COLOR\u BGR2GRAY)…>不支持的输入图像深度:>'VDepth::contains(depth)>,其中>'depth'为6(CV_64F)。您可能知道问题出在哪里?我试过颜色_