scipy ndimage过滤器中输出和返回值之间的差异

时间:2012-06-18 09:43:21

标签: python image-processing filter computer-vision scipy

我正在开始一个计算机视觉项目,我需要计算水平和垂直Sobel的衍生物。我和Numpy和Scipy一起使用Python,特别是ndimage.filters模块。

我无法理解返回值和输出参数之间的区别。

   output_x = np.zeros(image.shape)
   output_y = np.zeros(image.shape)
   filters.sobel(image, 1, output_x)
   filters.sobel(image, 0, output_y)

   return_val_1 = filters.sobel(image, axis=1)
   return_val_2 = filters.sobel(image, axis=0)

如果我绘制返回值图像和输出图像,我会得到不同的结果。为什么?你能帮我么?我很安静。

2 个答案:

答案 0 :(得分:0)

传入输出数组会将结果存储在该数组中,而不是创建一个新数组。

当你需要在现场操作以节省内存时,这非常方便。

指定output数组时,ndimage函数返回None。除此之外,没有任何区别。

答案 1 :(得分:0)

问题是数据类型。

_ni_support._get_outupt所做的是np.zeros(input.shape, input.dtype.name),其中input.dtype.name是uint8。 你所做的是np.zeros(input.shape),默认情况下数据类型是float。

我遇到了同样的问题,并通过查看源代码来计算。