예제 #1
0
def makeEdgeGauss(width, center, size=512):
    """Create a matrix of given size that switches from 0 to 1 using a gaussian profile
         31/5/11: Added to option to create an edge with no blur for staircase procedures, etc. RJS

    :params:
            width: (float) the sd of the gauss used to smooth as a fraction of the matrix size
            center: (float) the location of the center of the ramp as a fraction of the total matrix
            size: (int=256) width and height of the matrix
            """
    if width==0:
        edge = np.ones(size*3, float)
        centerLocation = int(size+center*size)
        edge[:centerLocation]=0
        shpEdge = (edge[size:size*2]-edge.min())/(edge.max()-edge.min())
        shpEdge.shape = (1,size)
        return np.tile(shpEdge, (size,1))*2-1
    else:
        edge = np.ones(size*3, float)#3x to achieve edge-padding
        centerLocation = int(size+center*size)
        edge[:centerLocation]=0
        gauss = filters.makeGauss(x=np.linspace(-1.0,1.0,size), mean=0, sd=width)/np.sqrt(2*np.pi*width**2)
        smthEdge = np.convolve(edge, gauss,'same')
        smthEdge = (smthEdge[size:size*2]-smthEdge.min())/(smthEdge.max()-smthEdge.min())#just take the middle section
        smthEdge.shape=(1,size)
        return np.tile(smthEdge,(size,1))*2-1
def makeRevEdgeGauss(width, center, size=512):
        edge = np.ones(size*3, float)#3x to achieve edge-padding
        centerLocation = int(size+center*size)
        edge[centerLocation:]=0
        gauss = filters.makeGauss(x=np.linspace(-1.0,1.0,size), mean=0, sd=width)/np.sqrt(2*np.pi*width**2)
        smthEdge = np.convolve(edge, gauss,'same')
        smthEdge = (smthEdge[size:size*2]-smthEdge.min())/(smthEdge.max()-smthEdge.min())#just take the middle section
        smthEdge.shape=(1,size)
        return np.tile(smthEdge,(size,1))*2-1
예제 #3
0
def makeEdgeGauss(width, center, size=512):
    """Create a matrix of given size that switches from 0 to 1 using a gaussian profile
    
    :params:
            width: (float) the sd of the gauss used to smooth as a fraction of the matrix size
            center: (float) the location of the center of the ramp as a fraction of the total matrix
            size: (int=256) width and height of the matrix
            """
    edge = np.ones(size * 3, float)  # 3x to achieve edge-padding
    centerLocation = int(size + center * size)
    edge[:centerLocation] = 0
    gauss = filters.makeGauss(x=np.linspace(-1.0, 1.0, size), mean=0, sd=width) / np.sqrt(2 * np.pi * width ** 2)
    smthEdge = np.convolve(edge, gauss, "same")
    smthEdge = (smthEdge[size : size * 2] - smthEdge.min()) / (
        smthEdge.max() - smthEdge.min()
    )  # just take the middle section
    smthEdge.shape = (1, size)
    return np.tile(smthEdge, (size, 1)) * 2 - 1
예제 #4
0
#def GaussSmooth(matrix, width, center, size):
#    """put an image/matrix through a Gaussian smoothing filter
#   
#    params:
#        matrix: array to be smoothed
#        width: (float) the sd of the gauss used to smooth as a fraction of the matrix size
#        center: (float) the location of the center of the ramp as a fraction of the total matrix
#        size: (int=256) width and height of the matrix
#            """
#        centerLocation = int(size+center*size)
#        matrix
       
from psychopy import visual, filters, event
import Image, scipy
import numpy as np
from scipy.signal import convolve2d

width = 0.5
picture = np.array(Image.open('Leaf512.jpg').transpose(Image.FLIP_TOP_BOTTOM))/127.5-1

gauss = filters.makeGauss(picture, mean=0, sd=width)/np.sqrt(2*np.pi*width**2)
smth = scipy.signal.convolve2d(picture, gauss, 'same')


myWin = visual.Window(size=(1024, 768), monitor = 'testMonitor', units = 'degs', 
        fullscr=False, allowGUI=True)

img = visual.PatchStim(myWin, tex=smth, units='deg', sf=(1/10.0), size=10.0)
img.draw()
myWin.flip()
event.waitKeys()