【问题标题】:Image derivative - Sobel filters in Python SciPy图像导数 - Python SciPy 中的 Sobel 过滤器
【发布时间】:2019-03-11 14:54:38
【问题描述】:

我正在阅读 Jan Erik Solem 的《使用 Python 编程计算机视觉》一书,最终草案(CC 许可证)可通过 here 获得。

在第 34 页上,显示了将 Sobel 过滤器应用于图像的结果,参见图 1.10,如下所示。当我运行书中的代码时,梯度幅度的图像,即面板 (d),看起来是反转的,见下文。

我的问题是,这只是因为作者反转了图像,还是有其他原因?

下面列出了 Python 代码,改编自本书并添加了绘图功能。


这些是使用书中代码生成的图像。

Python 代码

from PIL import Image
from numpy import *
from pylab import *
from scipy.ndimage import filters

im = array(Image.open('empire.jpg').convert('L'))

# Sobel derivative filters
imx = zeros(im.shape)
filters.sobel(im,1,imx)

imy = zeros(im.shape)
filters.sobel(im,0,imy)

magnitude = sqrt(imx**2+imy**2)

figure(figsize=(12,4))
gray()

subplot(1,4,1)
title('Oiginal')
axis('off')
imshow(im)

subplot(1,4,2)
title('imx')
axis('off')
imshow(imx)

subplot(1,4,3)
title('imy')
axis('off')
imshow(imy)

subplot(1,4,4)
title('magnitude')
axis('off')
imshow(magnitude)

savefig('sobel.png')
show()

示例代码中使用的图片

【问题讨论】:

    标签: python scipy sobel


    【解决方案1】:

    尝试imshow(magnitude, cmap='gray') 显式声明颜色图。如果还是倒置,请尝试cmap='gray_r' 使用倒置灰度颜色图。

    【讨论】:

    • imshow(magnitude, cmap='gray_r' 给出的图像如书中所示。因此,图像可能是使用反转灰度构建的。谢谢
    猜你喜欢
    • 2019-03-27
    • 1970-01-01
    • 2021-11-29
    • 2013-07-22
    • 2015-07-31
    • 2014-01-27
    • 1970-01-01
    • 1970-01-01
    • 2021-02-01
    相关资源
    最近更新 更多