【问题标题】:problem with the 2d interpolation method using scipy.ndimage.zoom使用 scipy.ndimage.zoom 的二维插值方法的问题
【发布时间】:2021-03-28 17:16:42
【问题描述】:

我有一张灰度图像。 我想对图像进行上采样,所以我使用了以下代码,

img = cv2.imread('unnamed.jpg')
img_1 = scipy.ndimage.zoom(img,3, order=1)
print(img.shape, img_1.shape)

输出是

(187, 250, 3) (561, 750, 9)

由于某种原因,我不能使用 plt.imshow(img_1) 因为它给出错误,

TypeError: Invalid shape (561, 750, 9) for image data

如果有人可以帮助我,我将不胜感激。

【问题讨论】:

  • 由于您使用的是 OpenCV,这是一个选项:img_1 = cv2.resize(img, (width * 3, height * 3), interpolation=cv2.INTER_CUBIC) 否则请参阅这篇描述如何避免在 RGB 通道上操作的帖子:stackoverflow.com/questions/37119071/…

标签: image-processing signal-processing


【解决方案1】:

您的图像看起来有 3 个通道,这意味着它不是灰度的。因此,要么先将其转换为灰度,然后应用zoom,或者,如果您想保持图像处于彩色模式,请不要在图像通道上应用zoom,因为它没有多大意义。

# 1st option returns grayscale image
img = cv2.imread('unnamed.jpg',0) #  returns grayscale image
img_1 = scipy.ndimage.zoom(img,3, order=1)

# 2nd option returns BGR image
img = cv2.imread('unnamed.jpg',1) #  returns RGB image
img_1 = scipy.ndimage.zoom(img,[3,3,1], order=1) # zoom should contain one value for each axis.

【讨论】:

  • 谢谢。对不起,我误以为照片是灰度的,我以前从未意识到频道。第二个选项对我有用。 :) :)
猜你喜欢
  • 2010-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-06
  • 1970-01-01
  • 2021-12-06
  • 1970-01-01
相关资源
最近更新 更多