Пример #1
0
def flatAzim(res, cone, ori=0.0, cycles=1.0, phase=0.0, elevation = 0.0):
    """Creates a grating defined either by S or LM in DKL space. The elevation
    can be changed whilst keeping the azimuth flat - in effect changing the position
    of the azimuth
    
    Warning: May generate values >1 or <-1
    
    :Parameters:
        res: integer
            the size of the resulting matrix on both dimensions (e.g 256)
        cone: 'LM' or 'S'
            which axis in DKL space the grating should be created in
        ori: float or int (default=0.0)
            the orientation of the grating in degrees
        cycles:float or int (default=1.0)
            the number of grating cycles within the array
        phase: float or int (default=0.0)
            the phase of the grating in degrees (NB this differs to most
            PsychoPy phase arguments which use units of fraction of a cycle)
        elevation: float or int (default=0.0)
            the angle that the azimuth will be changed to

    :Returns:
        a square numpy array of size resXres
        """

    gabor = filters.makeGrating(res, ori=ori, cycles = cycles, phase=phase)

    colorGabor = np.zeros((len(gabor), len(gabor), 3))
    colorGabor[:,:,0] = copy.copy(gabor)
    colorGabor[:,:,1] = copy.copy(gabor)
    colorGabor[:,:,2] = copy.copy(gabor)

    dklGabor = misc.rgb2dklCart(colorGabor)
    if cone=='LM':
        dklGabor = misc.cart2sph(dklGabor[:,:,0]*0.0, dklGabor[:,:,0]*0.0, dklGabor[:,:,0])
    if cone=='S':
        dklGabor = misc.cart2sph(dklGabor[:,:,0]*0.0, dklGabor[:,:,0], dklGabor[:,:,0]*0.0)
    if cone=='Lum':
        dklGabor = misc.cart2sph(dklGabor[:,:,0], dklGabor[:,:,0]*0.0, dklGabor[:,:,0]*0.0)

    temp = copy.copy(dklGabor[:,:,1])+1
    temp = (temp/np.abs(temp))*+elevation
    dklGabor[:,:,0] += temp

    rgbGabor = misc. dkl2rgb(dklGabor)
    return rgbGabor
    if thisCond=='lum':
        thisInfo['Chromaticity']=1
        thisInfo['Luminance']=1
        thisInfo['Chromatic Blur']='n'
        thisInfo['Luminance Blur']='y'
    if thisCond=='achrom':
        thisInfo['Chromaticity']=0
        thisInfo['Luminance']=1
        thisInfo['Chromatic Blur']='n'
        thisInfo['Luminance Blur']='y'
    for thisPicture in info['pictures']:
        #Import a picture, turn into an array and change the range from 0-255 to (-1)-1
        picture=np.array(Image.open(thisPicture).transpose(Image.FLIP_TOP_BOTTOM))/127.5-1

        #Change the picture from RGB to DKL
        thisDklPicture = misc.rgb2dklCart(picture, conversionMatrix=conversionMatrix)
        thisDklPicture = np.array(thisDklPicture)
        

        #Specific info for this staircase
        picInfo=copy.copy(thisInfo)
    #    thisInfo['thisPicture'] = thisPicture
    #    info['images']={thisPicture:thisDklPicture}
    #    info['images'][thisPicture]=thisDklPicture
        
        thisStair = data.StairHandler(startVal=info['startVal'], 
                                                    nReversals=info['nReversals'],
                                                    stepSizes=info['stepSizes'],
                                                    stepType='lin', 
                                                    nTrials=info['nTrials'],
                                                    nUp=info['nUp'],
Пример #3
0
    lmGrating = np.empty((128,128,3))
    lmGrating[:,:,0] = copy.copy(grating2)
    lmGrating[:,:,1] = copy.copy(grating2)
    lmGrating[:,:,2] = copy.copy(grating2)
    
    
    grating1 = makeSineGrating(128, cycles=10.0, amplitude=amp, frequency=5)
    lumGrating = np.empty((128,128,3))
    lumGrating[:,:,0] = copy.copy(grating1)
    lumGrating[:,:,1] = copy.copy(grating1)
    lumGrating[:,:,2] = copy.copy(grating1)
    
    
    print amp     #Current amplitude

    dklGratingLum = misc.rgb2dklCart(lumGrating)
    dklGratingLm = misc.rgb2dklCart(lmGrating)
    
    lum1 = copy.copy(dklGratingLum[:,:,0])
    lm1 = copy.copy(dklGratingLum[:,:,1])*0
    s1 = copy.copy(dklGratingLum[:,:,2])*0
    
    lum2 = copy.copy(dklGratingLm[:,:,0])
    lm2 = copy.copy(dklGratingLm[:,:,1])*0
    s2 = copy.copy(dklGratingLm[:,:,2])*0
    

    
    lumlm = (lum2)/2.0              #peturb
    lmlm = (lum1)/2.0                #straight
    lmlm = np.rot90(lmlm)           #rotated perturb
Пример #4
0
#Image statistics to analyse LM and S in natural images - February 2011

from psychopy import misc
import numpy as np
import copy
import Image

range = range(512)

#Import picture and convert from RGB to DKL
pictures = ["Leaf512.jpg", "Pansy512.jpg", "Pelican512.jpg", "Pumpkin512.jpg"]

picture=np.array(Image.open("Pumpkin512.jpg").transpose(Image.FLIP_TOP_BOTTOM))/127.5-1

dklPicture = misc.rgb2dklCart(picture)
dklPicture = np.array(dklPicture)

lum = copy.copy(dklPicture[:,:,0])
lm = copy.copy(dklPicture[:,:,1])
s = copy.copy(dklPicture[:,:,2])


print 'rms lm', lm.std()
print 'rms s', s.std()
print 'rms lum', lum.std()

#print np.min(lm)
#print np.max(lm)

#Calculate the range of lm, s and lum
print 'lum min', np.min(lum), 'lum max', np.max(lum)
Пример #5
0
    sizer = np.array(OrigPicture)

#Measure the size of the image in order to crop out the centre 512x512 block
#    print sizer.shape

    if len(sizer[0,:,:]>512):
        xremove = (len(sizer[0,:,:])-512)/2
    if len(sizer[:,0,:]>512):
        yremove = (len(sizer[:,0,:])-512)/2

    #Crop to centre 512x512
    box = (xremove, yremove, 512+xremove, 512+yremove)
    picture = np.array(OrigPicture.crop(box)) /127.5-1

#Convert to DKL and separate into channels
    dklPicture = misc.rgb2dklCart(picture, conversionMatrix=None)
    dklPicture = np.array(dklPicture)

    lum = copy.copy(dklPicture[:,:,0])
    lm = copy.copy(dklPicture[:,:,1])
    s = copy.copy(dklPicture[:,:,2])

#Run 2d Fast Fourier Transform on each Channel
    fftLum = fftpack.fft2(lum)
    fftLm = fftpack.fft2(lm)
    fftS = fftpack.fft2(s)

    F2Lum = fftpack.fftshift(fftLum)
    F2Lm = fftpack.fftshift(fftLm)
    F2S = fftpack.fftshift(fftS)