python - 本地二进制模式中的意外行为 - python skimage

标签 python image-processing scikit-image lbph-algorithm

我最近遇到了问题,python skimage 中的本地二进制模式方法产生了意外的结果。

看看下面的卡通例子。它在平坦的彩色背景上显示两个平坦的彩色圆圈。

circles

本地二进制模式(P=8 个样本,半径=1)输出为:

lbp

(图像以 jet 颜色进行颜色编码)。灰色正确代表 255。但是,蓝色是 85(二进制 01010101)

因此,虽然该方法正确地将背景和右侧的圆圈显示为 255,但它却将左侧的圆圈显示为 85。显然,skimage 中的局部二值模式方法认为该区域完全有噪声(因此交替二值模式 01010101 )。然而,事实并非如此,因为我已经仔细检查了上面以蓝色显示的区域中的各个像素,并且它们的值是相同的(即其平面颜色,就像平面颜色背景和其他平面色环一样)。

有人遇到过类似的问题吗?

如果您想复制此内容,请使用以下代码:

from skimage.feature import local_binary_pattern
from skimage.color import rgb2gray
import matplotlib.pyplot as plt

img = plt.imread('circles.png')
img = rgb2gray(img)

lbp = local_binary_pattern(img, 8, 1, 'default')
plt.imshow(lbp, cmap='nipy_spectral')
plt.title('Standard lbp (8,1)')

最佳答案

我猜这个问题是由于数字错误造成的。当使用

读取彩色图像时
img = plt.imread('circles.png')

你得到一个float32类型的数组,并在随后转换为灰度

img = skimage.color.rgb2gray(img)

生成的图像的类型为float64

我建议您避免中间步骤。您可以从一开始就以 double (即 float64)读取图像,如下所示:

In [63]: from skimage.feature import local_binary_pattern

In [64]: from skimage import io

In [65]: img = io.imread('circles.png', as_grey=True)

In [66]: img.dtype
Out[66]: dtype('float64')

In [67]: lbp = local_binary_pattern(img, 8, 1, 'default')

In [68]: io.imshow(lbp/255., cmap='nipy_spectral')
Out[68]: <matplotlib.image.AxesImage at 0x10bdd780>

results

关于python - 本地二进制模式中的意外行为 - python skimage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42322400/

相关文章:

python - 处理数组 : how to avoid a "for" statement

image-processing - 用于创建 PNG 8 位透明图像的软件

python - 如何用每个像素的 RGB 值构建图像

c++ - 如何找到8?16?32? opencv中的位图?

python - Python 3.x 中的 "bwlabeln (with 18 and 26-connected neighborhood)"相当于什么?

python - 电子邮件不使用 django 1.9 发送

c++ - python 代码到 c++ lib 或 dll

python - 在 AWS 上运行 Twisted 的问题

python - 使用 Python 图像处理分割生物样本的照片以提取感兴趣的圆形区域

image - 使用不同尺寸但相同数量的 HoG 特征的图像训练分类器