【问题标题】:How do I pad values in the array so that I get this?如何在数组中填充值以便得到这个?
【发布时间】:2023-03-06 12:17:01
【问题描述】:

我正在尝试从较小的图像(左侧)中获取大图像。 这是 15x15 内核,我需要获取大图像。如何将值填充到数组中以获得大图像? 我是新手。解释将不胜感激。

【问题讨论】:

    标签: python image-processing fft imagefilter gaussianblur


    【解决方案1】:

    要完成这个转换,你要先pad the image,然后用ifftshift将原点移动到左上角:

    import numpy as np
    
    K = np.zeros((15,15))
    K[7,7] = 1        # not exactly the 15x15 kernel on the left, but similar
    sz = (256, 256)   # the output sizes
    after_x = (sz[0] - K.shape[0])//2
    before_x = sz[0] - K.shape[0] - after_x
    after_y = (sz[1] - K.shape[1])//2
    before_y = sz[1] - K.shape[1] - after_y
    K = np.pad(K, ((before_x, after_x), (before_y, after_y)), 'constant')
    K = np.fft.ifftshift(K)
    

    请注意,此处的焊盘尺寸经过精心选择,以保留原点的正确位置,这在过滤中很重要。对于奇数大小的内核,原点位于中间像素。对于在中间没有像素的均匀大小的内核,原点是从真正中心向右下方的像素。在这两种情况下,此位置都是使用K.shape // 2 计算的。

    【讨论】:

    • 非常感谢您的回答。
    猜你喜欢
    • 1970-01-01
    • 2023-01-13
    • 1970-01-01
    • 1970-01-01
    • 2016-06-05
    • 2016-02-18
    • 2020-12-02
    • 1970-01-01
    • 2012-06-04
    相关资源
    最近更新 更多