對於一個實驗,我需要一個整個窗口上的高斯濾波器,如中間部分顯示。由於我使用的是PsychoPy,基本上,我需要一個N×M數組(N和M是窗口的像素大小),中間的數組(其中底層的刺激在邊緣可見-1),然後我可以使用這個數組作爲內GratingStim口罩。 到目前爲止,我一直在努力 ndimage.filters.gaussian_filter(filter_input,差= 7)我如何獲得一個高斯內核陣列來過濾我的圖像
,但我有一些麻煩與此funcion。如果filter_input是N×M的矩陣如果filter_input是一個帶有隨機數的矩陣,它會改變它們,但我仍然沒有得到我期望的結果,我意識到PsychoPy的面具只允許-1和1之間的值,但因爲它現在在下面的代碼中,所以我不應該能夠看到任何東西,因爲蒙版是-1。
所以,更具體地說: 爲什麼ndimage.filters.gaussian_filter(filter_input,sigma = 7)的行爲就像它一樣?我怎麼能得到它分配給NxM矩陣中的每個點的值,使得分配的值具有高斯2d分佈?後來我可以砍掉高於1且低於-1的值。
我很抱歉,如果我的問題是微不足道的,我一直在做一些PsychoPy編程,但我是新來numpy的和SciPy的...
感謝您的幫助!
下面是一些示例代碼:
# -*- coding: utf-8 -*-
from psychopy import visual, event
import numpy as np
from scipy import ndimage
win = visual.Window([500,500])
#draw rectangle
perc25 = visual.Rect(win, width = 0.6,height=0.4, lineColor='red',fillColor = 'red', pos=(0.0, 0.1)) #notloesu
perc25.draw()
#add circle with fuzzy edges
perc75 = visual.GratingStim(win, sf=0, size=0.5, color='green',pos=(0.0, -0.1), mask = 'raisedCos', maskParams={'fringeWidth':0.6})
perc75.draw()
#create the matrix that should result in a gaussian filter laied centrally over the entire window
#desired Result: some red in the upper part of the visible circle in the middle, the rest beeing green
filter_input = (np.ones([500,500]))*(-1.)
gaussian = ndimage.filters.gaussian_filter(filter_input, sigma = 0.2)
print(filter_input == gaussian)
#i know it's ugly, I just can't think of another way to apply the filter to the entire image and I haven't found anything in the internet
unnecesary_stim_to_get_the_mask_over_the_window = visual.GratingStim(win, sf=0, size=0.0000001, color='green',pos=(0, 0), mask = gaussian)
unnecesary_stim_to_get_the_mask_over_the_window.draw()
win.flip()
event.waitKeys()
比較遺憾的是漫長的等待,感謝您的輸入,這讓我進一步想在哪裏結果。 – lilla