- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想使用 Python 从 RGB 图像的主要特征周围去除噪声“五彩纸屑”。理想情况下,此过程将使示例图像中心的大特征( Blob )保持不变。即是否可以仅在其面积低于给定值时去除噪声?
我曾尝试在示例图像上使用 OpenCV 的 fastNlMeansDenoisingColored
函数(见下文),但这会从图像的其余部分移除重要信号。
这是示例图片:
也可以是downloaded here .
import cv2
import matplotlib.pyplot as plt
import numpy as np
img = cv2.imread('example.png')
dst = cv2.fastNlMeansDenoisingColored(img,None,10,7,21)
# Original
plt.imshow(img)
plt.show()
print(np.nanmin(img),np.nanmax(img))
# denoised
plt.imshow(dst)
print(np.nanmin(dst),np.nanmax(dst))
plt.show()
# difference
plt.imshow(img-dst)
plt.show()
最佳答案
如果您只想要中央的 Blob ,您可以选择寻找轮廓并选择面积最大的那个。
代码:
#--- convert image to grayscale ---
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
#--- Perform Otsu threshold ---
ret2, th2 = cv2.threshold(imgray,0,255,cv2.THRESH_BINARY + cv2.THRESH_OTSU)
cv2.imshow('Threshold', th2)
它产生一个二值图像:
#--- Finding contours using the binary image ---
_, contours, hierarchy = cv2.findContours(th2, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
#--- finding the contour with the maximum area ---
big_contour = 0
max_area = 0
for cnt in contours:
if (cv2.contourArea(cnt) > max_area):
max_area = cv2.contourArea(cnt)
big_contour = cnt
#--- creating a mask containing only the biggest contour ---
mask = np.zeros(imgray.shape)
cv2.drawContours(mask, [big_contour], 0, (255,255,255), -1)
cv2.imshow('Mask', mask)
#--- masking the image above with a copy of the original image ---
im2 = im.copy()
fin = cv2.bitwise_and(im2, im2, mask = mask.astype(np.uint8))
cv2.imshow('Final result', fin)
关于python - 基于空间维度去除图像噪声,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51329338/
给定一个字符串"5 900 000" 我想通过以下模式使用 gsub 去除空格: gsub(/\s/, '') 但这似乎行不通。也没有: gsub(' ', '') 最佳答案 如果你想就地替换,你需要
我编写了一个程序来抓取网站以获取数据并输出到 Excel 表。该程序使用 Microsoft Visual Studio 2010 用 C# 编写。 大多数时候,我从网站获取内容、解析内容并将数据存储
在 MS Access 2007 项目报告中,我有以下(已编辑)查询: SELECT SomeCol FROM SomeTable 问题是, SomeCol 显然包含一些不可见的字符。例如,我看到一个
如 Removing left recursion 中所述,有两种方法可以去除左递归。 使用一些过程修改原始语法以删除左递归 写文法原来没有左递归 人们通常使用什么来删除(没有)ANTLR 的左递归?
我在 CoreData 中存储了一堆艺术家,并希望按名称对它们进行排序,但忽略前缀“the”。例如,“The Beatles”将被排序为“Beatles”,有点像 iTunes/iPod 的做法。 因
我有一个 WebView ,我想从中删除弹性。现在,当滚动小于 webview 的页面时,它会产生弹性效果,显示下面的背景。我想删除这个。 我尝试过执行以下操作,但没有成功。它找到了 WebDynam
我正在调查我们公司使用 Prometheus 从我们在 Kubernetes 上运行的实验中收集统计数据。有计划使用标签来标记我们的云/集群中特定实验的名称。这意味着我们将生成大量标签,这些标签会随着
我正在添加聚合物元素。我想在单击其(自己的)图像时删除元素(自我)。根据封装,我将不得不让 parent 删除 child 。但这也需要为母体生成聚合物元素(我在这里吗??)。 children.ad
现在如果我点击按钮 A,按钮 B 会显示 DropShadow 效果: Private Sub ButtonA_Click(ByVal sender As System.Object, ByVal
我尝试过这个,但它对我不起作用: char * remove_nl(char * newstr) { newstr = strdup(newstr); newstr[strlen(ne
我陷入了两难境地。我有一个图像,我想占据网页的背景。我希望它横跨屏幕的宽度和高度,并保持那个尺寸。当我使用 标签,我不知道如何将它拉伸(stretch)到没有白条的屏幕上。 wspace 和 hspa
Jade .foo .foo 结果 想要的结果 在 haml 中我会做类似 .foo>< 的事情但这在 Jade 中不起作用。我已经搜索并空手而归如何处理这个问题。我如何达到预期的结果
我是 Maven 的新手,当我尝试将我当前的项目从使用 Ant 转换为 -> 使用 Maven 时遇到了问题。 那个项目需要很多 Jar,我在 mvnrepository 上查找这些 jar 并将它们
我需要一个正则表达式来删除 xml 标记开头和结尾之间的空格。例如:有人创建 xml 并将其发送给我,这样我就可以验证、签名并发送到网络服务。 为此,我需要删除标签开头和结尾之间的空格: String
我写了几个方法来将项目添加到数组中,如果它们已经在数组中,它们将被忽略。在对数据结构做了一些研究之后,我意识到我可以通过简单地将它们放在一个集合中来摆脱重复(特别是因为我不关心对象的顺序)。然而,在玩
使用 HighCharts,我想移除 SVG 曲线上的抗锯齿。 到目前为止,我正在使用这个: $('path').each(function(i,j){$(j).attr('shape-renderi
由于某些奇怪的原因(黑色但不是黑色部分),我的 SeekBar 和拇指后面出现随机阴影。我该如何摆脱它? 我的搜索栏: 拇指.xml progress_appearance.xml(有一些
我有一个 Url,我想获取路径部分但没有尾随文件名。如果 Url 是 http://my.com/dir1/dir2/file.ext 那么我想获取 /dir1/dir2 . 我已经尝试了各种拆分(l
我有这个字符串: dataSourceURL = URL(string:"https://api.abc.com/api/p4/products?pid=uid8225&format=json&off
在我的网页中,我有一个菜单 (HorizontalPanel) 应该隐藏在页面的底部。为此,我尝试使用 RootLayoutPanel 类并在其中添加一个 south 小部件,我成功地做到了。但问
我是一名优秀的程序员,十分优秀!