【问题标题】:How to normalize scipy's convolve2d when working with images?处理图像时如何标准化 scipy 的 convolve2d?
【发布时间】:2016-08-14 02:05:42
【问题描述】:

我正在使用 scipy 的 convolve2d:

for i in range(0, 12):
            R.append(scipy.signal.convolve2d(self.img,  h[i], mode = 'same'))

卷积后所有值的大小都为 10000 秒,但考虑到我正在处理图像,我需要它们在 0-255 的范围内。如何规范化?

【问题讨论】:

标签: python opencv numpy scipy


【解决方案1】:

假设您想在一张图像中进行归一化,您可以简单地使用 im_out = im_out / im_out.max() * 255

您还可以标准化内核或原始图像。

以下示例。

import scipy.signal
import numpy as np
import matplotlib.pyplot as plt
from skimage import color
from skimage import io


im = plt.imread('dice.jpg')
gray_img = color.rgb2gray(im)

print im.max()

# make some kind of kernel, there are many ways to do this...
t = 1 - np.abs(np.linspace(-1, 1, 16))
kernel = t.reshape(16, 1) * t.reshape(1, 16)
kernel /= kernel.sum()   # kernel should sum to 1!  :) 

im_out =scipy.signal.convolve2d(gray_img,  kernel, mode = 'same')

im_out = im_out / im_out.max() * 255

print im_out.max()

plt.subplot(2,1,1)
plt.imshow(im)
plt.subplot(2,1,2)
plt.imshow(im_out)
plt.show()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-10
    • 2020-10-09
    • 2017-03-07
    • 2015-09-17
    • 1970-01-01
    • 2014-07-30
    • 1970-01-01
    • 2015-03-13
    相关资源
    最近更新 更多