简体   繁体   English

可变大小的对称矩阵输出

[英]Variable size symmetrical matrix output

I am trying to create a function for the Mexican Hat wavelet, that allows for a variable output size (3x3, 5x5, 15x15, etc). 我正在尝试为墨西哥帽小波创建一个函数,以允许可变的输出大小(3x3、5x5、15x15等)。 The code below only works (gets a symmetrical shape) for a 5x5 input, but if it try to obtain a 15x15 output (d = 15), the result does not center the highest value in the middle. 下面的代码仅对5x5输入有效(获得对称的形状),但是如果尝试获得15x15输出(d = 15),则结果不会将最高值居中。

a = np.empty([5, 5])

def mex(array):
    h = np.empty_like(array, dtype=np.float)
    print "Say the filter size (d)"
    d = int(raw_input("> "))
    for line in range(array.shape[0]):
        for col in range(array.shape[1]):
            x = col - (d - 1)/2
            y = (d - 1)/2 - line
            value = 0
            value = (1 - x**2 - y**2) * math.exp(-((x**2)+(y**2))/2)
            h[line, col] = value
    print h
    return h

b = mex(a)

This is the result for 5x5 input: 这是5x5输入的结果: 这是5x5输入的结果

And this is the result for 15x15: 这是15x15的结果:

在此处输入图片说明

Thanks for any help! 谢谢你的帮助! :) :)

You are only showing the bottom left corner of the hat. 您仅显示帽子的左下角。 Because your mex function starts by creating a 5 x 5 matrix you then fill that with just that corner of the 15 x 15 thing you are trying to create. 因为您的混合函数是通过创建5 x 5矩阵开始的,所以您只用要创建的15 x 15物体的那个角填充该矩阵。 Which of course is not symmetrical. 当然哪个不是对称的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM