代码之家  ›  专栏  ›  技术社区  ›  Giuseppe Angora

为什么scipy.ndimage zoom添加新频道?

  •  0
  • Giuseppe Angora  · 技术社区  · 7 年前

    当我发现那条巨蟒时我很惊讶 scipy.ndimage.zoom 执行缩放时自动添加新频道:

    from scipy.misc import imread
    from scipy.ndimage import zoom
    img = imread('lena.jpg')
    img=imread('lena.jpg')
    img.shape
    (468, 792, 3)
    x = zoom(img, 1.0)
    x.shape
    (468, 792, 3)
    x = zoom(img, 1.5)
    x.shape
    (702, 1188, 4)
    x = zoom(img, 2)
    x.shape
    (936, 1584, 6)
    

    宽度,高度尺寸都是正确的,我不知道从哪里来的其他尺寸。

    这种奇怪的行为只表现在彩色图像上:

    x = zoom(img[:, :, 0], 2)
    x.shape
    (936, 1584)
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   user6655984    7 年前

    ndimage.zoom 对频道(或图像)一无所知。它使用一个n维数组进行操作。如果你给一个有形状的数组 (9, 5, 3) 并要求放大系数为2,它将生成一个具有形状的数组 (9*2, 5*2, 3*2) 哪个是 (18, 10, 6) .

    当然,当第三个轴是颜色通道时,这不是您想要的。使用每轴缩放,将最后一个轴的缩放设置为1:

    zoom(img, (2, 2, 1))
    
    推荐文章