【问题标题】:RGB image convolution from scipy来自 scipy 的 RGB 图像卷积
【发布时间】:2019-09-29 15:07:40
【问题描述】:

我正在尝试使用来自 scipy.signal 的卷积来创建一个函数来突出图像中的边缘。这是我的代码:

def highlight_edges(self):
    window = np.array([[-1, -1, -1],
                       [-1, 9, -1],
                       [-1, -1, -1]])

    if self.image_data.ndim == 2:
        # gray image
        self.image_data = convolve2d(self.image_data, window, mode='same', boundary='symm')
    elif self.image_data.shape[2] == 3:
        # rgb image
        # for each channel:
        for i in range(3):
            self.image_data[:, :, i] = convolve2d(self.image_data[:, :, i], window, mode='same', boundary='symm')

它适用于灰度图像,但对于 RGB 图像它返回一个混乱。我怀疑,可能会有一些溢出,但我不确定。以下是图片:

原图:

执行highligh_edges函数后:

【问题讨论】:

  • 您能否添加加载图像的方式,并可能使其成为其类之外的可运行函数,以便我们帮助您调试?

标签: python image scipy


【解决方案1】:

有点晚了,但我认为标准化图像会解决它。在应用卷积之前尝试将图像除以 255。否则,我们可以实际测试的功能会更好......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-25
    • 2019-05-03
    • 2017-08-21
    • 2018-06-25
    • 1970-01-01
    • 1970-01-01
    • 2013-02-07
    • 1970-01-01
    相关资源
    最近更新 更多