Python中文
首页
教程
问答
标签
搜索
登录
注册
在没有数据像素时对图像应用过滤器
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我有一个包含许多无数据像素的图像。图像为2d numpy数组,无数据值为“无”。每当我尝试在它上应用过滤器时,似乎内核中都会考虑到none值,并使我的像素消失</p> <p>例如,我有这样的图像:<br/> <a href="https://i.stack.imgur.com/Ggxmk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ggxmk.png" alt="enter image description here"/></a></p> <p>我已尝试使用此函数对其应用lee筛选器(取自<a href="https://stackoverflow.com/questions/39785970/speckle-lee-filter-in-python">Speckle ( Lee Filter) in Python</a>):</p> <pre><code>from scipy.ndimage.filters import uniform_filter from scipy.ndimage.measurements import variance def lee_filter(img, size): img_mean = uniform_filter(img, (size, size)) img_sqr_mean = uniform_filter(img**2, (size, size)) img_variance = img_sqr_mean - img_mean**2 overall_variance = variance(img) img_weights = img_variance / (img_variance + overall_variance) img_output = img_mean + img_weights * (img - img_mean) return img_output </code></pre> <p>但结果如下:<br/> <a href="https://i.stack.imgur.com/0We7F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0We7F.png" alt="enter image description here"/></a></p> <p>警告:</p> <blockquote> <p>UserWarning: Warning: converting a masked element to nan. dv = np.float64(self.norm.vmax) - np.float64(self.norm.vmin)</p> </blockquote> <p>我还尝试使用图书馆<a href="https://erdogant.github.io/findpeaks/pages/html/Denoise.html" rel="nofollow noreferrer">findpeaks</a></p> <pre><code> from findpeaks import findpeaks import findpeaks #lee enhanced filter image_lee_enhanced = findpeaks.lee_enhanced_filter(img, win_size=3, cu=0.25) </code></pre> <p>但我得到了同样的空白图像。 当我在同一张图像上使用中值滤波时,ndimage的工作没有问题</p> <p><strong>我的问题是如何在不让“无”值中断结果的情况下对图像运行这些过滤器?</strong></p> <p>编辑:我不喜欢将无值像素设置为0,因为像素范围值在-50-1之间(是索引值)。此外,我担心如果我将其更改为任何其他值(例如9999),它也会影响过滤器(我错了吗?)</p> <p><strong>编辑2:</strong> <strong>我已经阅读了Cris Luengo的答案,并尝试应用与scipy.ndimage中值滤波器类似的东西,因为我意识到结果也不正确。</strong></p> <p>这是原始图像:</p> <p><a href="https://i.stack.imgur.com/8Gb7A.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8Gb7A.png" alt="enter image description here"/></a></p> <p>我已尝试屏蔽空值:</p> <pre><code> idx = np.ma.masked_where(img,img!=None)[:,1] median_filter_img = ndimage.median_filter(img[idx].reshape(491, 473), size=10) zeros = np.zeros([img.shape[0],img.shape[1]]) zeros[idx] = median_filter_img </code></pre> <p>结果如下所示(颜色较深,以便在边缘看到问题):</p> <p><a href="https://i.stack.imgur.com/HJRyb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HJRyb.png" alt="enter image description here"/></a></p> <p>可以看出,边值似乎是无值的影响。 我也和img一起做过=0,但遇到了相同的问题</p> <p>(仅添加:像素值在1到-35之间)</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>似乎一个简单的解决方案是将非值设置为零。我不知道你会如何解决这个问题,因为大多数图像处理内核都需要一些值来帮助你应用。 a[numpy.argwhere(a==None)]=0</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在PyObj中使用respondsToSelector和performSelector
1 回答
如何在pyobj中停止线程
3 回答
如何在pyobj中生成线程
6 回答
如何在pyodbc中为记录集指定游标类型?
4 回答
如何在pyodbc中从用户处获取表名,同时避免SQL注入?
10 回答
如何在pyodbc中使用executemany运行多个SELECT查询
8 回答
如何在pyodbc中同时在n个游标上并行运行n个进程?
6 回答
如何在pyodbc中控制连接池的大小?
3 回答
如何在pyodbc中自动调用fetchall()而不进行异常处理?
3 回答
如何在pyODBC查询中参数化日期戳?
2 回答
如何在pyodbc输出转换器函数中解压sqlserver DATETIME?
5 回答
如何在pyodb中安装所有驱动程序
5 回答
如何在pyodb嵌套循环中调用不同的查询
9 回答
如何在pyomo.environ公司modu装置
5 回答
如何在Pyomoconstraints中建模逻辑或量词
4 回答
如何在Pyomo中为约束使用数组
7 回答
如何在pyomo中使用集和范围集的多级索引?
2 回答
如何在PYOMO中分配伪二进制变量
9 回答
如何在Pyomo中创建OR约束?
5 回答
如何在Pyomo中动态地将变量添加到列表中?
4 回答