I am trying to create a function for the Mexican Hat wavelet, that allows for a variable output size (3x3, 5x5, 15x15, etc). 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.
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:
And this is the result for 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. Which of course is not symmetrical.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.