[visionegg] uneven grating
- From: "matvey bossis" <bosism@xxxxxxxxx>
- To: visionegg@xxxxxxxxxxxxx
- Date: Wed, 14 Feb 2007 13:39:42 +0200
Hi
I am trying to generate a square wave color grating using
SinGrating2D. I have two problems:
1. The grating is uneven, for some reason. I get thicker and thinner stripes.
2. The border between the circles is blurred. I think also the borders
between the stripes is not sharp enough.
__________________________________________________
#!/usr/bin/env python
"""Colored sine wave grating in circular mask"""
############################
# Import various modules #
############################
import VisionEgg
VisionEgg.start_default_logging(); VisionEgg.watch_exceptions()
from VisionEgg.Core import *
from VisionEgg.FlowControl import Presentation, FunctionController
from VisionEgg.Gratings import SinGrating2D
from VisionEgg.Textures import Mask2D
from VisionEgg.MoreStimuli import *
from math import *
#####################################
# Initialize OpenGL window/screen #
#####################################
screen = get_default_screen()
######################################
# Create sinusoidal grating object #
######################################
mask = Mask2D(function='circle', # also supports 'circle'
radius_parameter=30, # sigma for gaussian, radius for
circle (units: num_samples)
num_samples=(512,512)) # this many texture elements in
mask (covers whole size specified below)
mask2 = Mask2D(function='circle', # also supports 'circle'
radius_parameter=16, # sigma for gaussian, radius for
circle (units: num_samples)
num_samples=(512,512)) # this many texture elements in
mask (covers whole size specified below)
# NOTE: I am not a color scientist, and I am not familiar with the
# needs of color scientists. Color interpolation is currently done in
# RGB space, but I assume there are other interpolation methods that
# people may want. Please submit any suggestions.
stimulus = SinGrating2D(color1 = (0.294, 0.229, 0.0667), #
RGB (alpha ignored if given)
color2 = (0.239, 0.212, 0.467), #
RGB (alpha ignored if given)
contrast = 10,
# pedestal = 0.95,
mask = mask, # optional
position = ( screen.size[0]/2.0,
screen.size[1]/2.0 ),
anchor = 'center',
size = ( screen.size[1]*4 ,
screen.size[1]*4 ),#( 300.0 , 300.0 ),
spatial_freq = 40.0 / screen.size[0], #
units of cycles/pixel
temporal_freq_hz = 0,
orientation = 0 )
backgr_stimulus = SinGrating2D(color1 = (0.294, 0.229,
0.0667), # RGB (alpha ignored if given)
color2 = (0.239, 0.212, 0.467), #
RGB (alpha ignored if given)
contrast = 10,
# pedestal = 0.95,
# mask = mask, # optional
position = ( screen.size[0]/2.0,
screen.size[1]/2.0 ),
anchor = 'center',
size = ( screen.size[1]*4 , screen.size[0]*4 ),
spatial_freq = 40.0 / screen.size[0], #
units of cycles/pixel
temporal_freq_hz = 0,
orientation = 0 )
backgr_stimulus2 = SinGrating2D(color1 = (0.294, 0.229,
0.0667), # RGB (alpha ignored if given)
color2 = (0.239, 0.212, 0.467), #
RGB (alpha ignored if given)
contrast = 10,
# pedestal = 0.95,
mask = mask2, # optional
position = ( screen.size[0]/2.0,
screen.size[1]/2.0 ),
anchor = 'center',
size = ( screen.size[1]*4 ,
screen.size[1]*4 ),#( 300.0 , 300.0 ),
spatial_freq = 40.0 / screen.size[0], #
units of cycles/pixel
temporal_freq_hz = 0,
orientation = 0 )
backgr_stimulus4 = SinGrating2D(color1 = (0.3529, 0.3529,
0.3529), # RGB (alpha ignored if given)
color2 = (0.3529, 0.3529, 0.3529),
# RGB (alpha ignored if given)
contrast = 0,
# pedestal = 0.95,
mask = mask2, # optional
position = ( screen.size[0]/2.0,
screen.size[1]/2.0 ),
anchor = 'center',
size = ( screen.size[1]*4 ,
screen.size[1]*4 ),#( 300.0 , 300.0 ),
spatial_freq = 40.0 / screen.size[0], #
units of cycles/pixel
temporal_freq_hz = 0,
orientation = 0 )
backgr_stimulus3 = SinGrating2D(color1 = (0.3529, 0.3529,
0.3529), # RGB (alpha ignored if given)
color2 = (0.3529, 0.3529, 0.3529),
# RGB (alpha ignored if given)
contrast = 0,
# pedestal = 0.95,
# mask = mask2, # optional
position = ( screen.size[0]/2.0,
screen.size[1]/2.0 ),
anchor = 'center',
size = ( screen.size[1]*4 ,
screen.size[1]*4 ),#( 300.0 , 300.0 ),
spatial_freq = 40.0 / screen.size[0], #
units of cycles/pixel
temporal_freq_hz = 0,
orientation = 0 )
######################################
# Create fixation point stimulus #
######################################
fixation = FilledCircle(
anchor = 'center',
position = (screen.size[0]/2.0, screen.size[1]/2.0),
radius = 5.0,
color = (255, 0, 0) # Draw it in red
)
def pedestal_func(t):
# Calculate pedestal over time. (Pedestal range [0.1,0.9] and
# contrast = 0.2 limits total range to [0.0,1.0])
temporal_freq_hz = 0.2
return 0.4 * sin(t*2*pi * temporal_freq_hz) + 0.5
def phase_func(t):
temporal_freq_hz = 4
return 180*round(t*temporal_freq_hz)
###############################################################
# Create viewport - intermediary between stimuli and screen #
###############################################################
viewport = Viewport( screen=screen,
stimuli=[backgr_stimulus,stimulus,backgr_stimulus2,fixation] )
viewport1 = Viewport( screen=screen,
stimuli=[backgr_stimulus3,stimulus,backgr_stimulus4,fixation] )
viewport2 = Viewport( screen=screen, stimuli=[backgr_stimulus3, fixation] )
########################################
# Create presentation object and go! #
########################################
yellow1=(0.306,0.231,0)
yellow2=(0.294, 0.229, 0.0667)
yellow3=(0.286,0.224,0.153)
yellow4=yellow2
yellow5=(0.286,0.224,0.145)
yellow6=(0.302,0.235,0.118)
blue1=(0.063,0.003,0.573) # corrected
blue2=(0.031, 0.004, 0.259) # corrected
blue3=(0.259, 0.204, 0.267) # corrected
blue4=(0.239, 0.212, 0.467)
blue5=(0.267,0.22,0.298)
blue6=(0.224,0.188,0.749)
magenta1=(0.533,0.129,0.4)
magenta2=(0.341,0.2,0.255)
magenta3=magenta1
magenta4=(0.867,0.004,0.647)
magenta5=magenta2
green1=(0.255, 0.384, 0.224) # corrected
green2=(0.259,0.271,0.204) # corrected
green3=(0.137,0.267,0.106) #green1
green4=(0.070,0.294,0.055)
green5=(0.224,0.235,0.169) #green2
green1=(78/255.0,92/255.0,78.0/255.0) # 20
green2=(62/255.0,108/255.0,62/255.0) # 65
green3=(46/255.0,124/255.0,46/255.0) # 110
green4=(23/255.0,147/255.0,23/255.0) # 175
green5=(0/255.0,70/255.0,0/255.0) # 240
magenta1=(138/255.0,117/255.0,138/255.0) # 20
magenta2=(163/255.0,92/255.0,163/255.0) # 65
magenta3=(186/255.0,69/255.0,186/255.0) # 110
magenta4=(221/255.0,34/255.0,221/255.0) # 175
magenta5=(230/255.0,0/255.0,230/255.0) # 240 default
red1=(138/255.0,117/255.0,117/255.0) # 20
red2=(163/255.0,92/255.0,92/255.0) # 65
red3=(186/255.0,69/255.0,69/255.0) # 110
red4=(221/255.0,34/255.0,34/255.0) # 175
red5=(255/255.0,0/255.0,0/255.0) # 240
yellow1=(138/255.0,138/255.0,117/255.0) # 20
yellow2=(163/255.0,163/255.0,92/255.0) # 65
yellow3=(186/255.0,186/255.0,69/255.0) # 110
yellow4=(221/255.0,221/255.0,34/255.0) # 175
yellow5=(255/255.0,255/255.0,0/255.0) # 240
blue1=(117/255.0,117/255.0,138/255.0) # 20
blue2=(92/255.0,92/255.0,163/255.0) # 65
blue3=(69/255.0,69/255.0,186/255.0) # 110
blue4=(34/255.0,34/255.0,221/255.0) # 175
blue5=(0/255.0,0/255.0,255/255.0) # 240
cyan1=(117/255.0,138/255.0,138/255.0) # 20
cyan2=(92/255.0,163/255.0,163/255.0) # 65
cyan3=(69/255.0,186/255.0,186/255.0) # 110
cyan4=(34/255.0,221/255.0,221/255.0) # 175
cyan5=(0/255.0,173/255.0,173/255.0) # 240, corrected w/magenta5
red6=(156,0,0) # 240, corrected
green6=(0,87,0) # 240, corrected
blue6=(0,0,154) # 240, corrected
cyan6=(0,91,91) # 240
yellow6=(83,83,0) # 240
magenta6=(105,0,105) # 240
green7=(0,178,0)
red8=(214,0,0)
red5=(188/255.0,0,0)
green5=(0,125/255.0,0)
blue5=(0,0,212/255.0) # sat=240, br=(90,90,90)
cyan5=(0,104/255.0,104/255.0)
yellow5=(113/255.0,113/255.0,0)
magenta5=(147/255.0,0,147/255.0)
red3=(161/255.0,60/255.0,60/255.0) # sat=110
green3=(43/255.0,116/255.0,43/255.0) # sat=110
blue3=(62/255.0,62/255.0,169/255.0) # sat=111
cyan3=(37/255.0,100/255.0,100/255.0) # sat=110
yellow3=(100/255.0,100/255.0,37/255.0) # sat=110
magenta3=(129/255.0,48/255.0,129/255.0) # sat=110
red1=(100/255.0,85/255.0,85/255.0) # sat=19
green1=(79/255.0,94/255.0,79/255.0) # sat=21
blue1=(85/255.0,85/255.0,100/255.0) # sat=19
cyan1=(81/255.0,96/255.0,96/255.0) # sat=20
yellow1=(94/255.0,94/255.0,79/255.0) # sat=21
magenta1=(96/255.0,81/255.0,96/255.0) # sat=20
magenta3p=(152/255.0,88/255.0,154/255.0) # sat=66
green3p=(100/255.0,160/255.0,100/255.0) # sat=58
gray0=(0.0,0.0,0.0)
gray3=(90/255.0,90/255.0,90/255.0)
gray5=(180/255.0,180/255.0,180/255.0)
stimulus.parameters.color1=blue1
stimulus.parameters.color2=yellow1
#stimulus.parameters.orientation= 275.0
backgr_stimulus.parameters.color1=blue2
backgr_stimulus.parameters.color2=yellow2
#backgr_stimulus.parameters.orientation=270
backgr_stimulus2.parameters.color1=blue2
backgr_stimulus2.parameters.color2=yellow2
#backgr_stimulus2.parameters.orientation=270
p = Presentation(go_duration=(0.75,'seconds'),viewports=[viewport])
p1 = Presentation(go_duration=(0.5,'seconds'),viewports=[viewport2])
p2 = Presentation(go_duration=(0.75,'seconds'),viewports=[viewport1])
##p.add_controller(stimulus,'pedestal',FunctionController(during_go_func=pedestal_func))
p.add_controller(stimulus,'phase_at_t0',FunctionController(during_go_func=phase_func))
p.add_controller(backgr_stimulus,'phase_at_t0',FunctionController(during_go_func=phase_func))
p.add_controller(backgr_stimulus2,'phase_at_t0',FunctionController(during_go_func=phase_func))
p2.add_controller(stimulus,'phase_at_t0',FunctionController(during_go_func=phase_func))
stimulus.parameters.color1=magenta3
stimulus.parameters.color2=yellow3
backgr_stimulus.parameters.color1=green5
backgr_stimulus.parameters.color2=blue5
backgr_stimulus2.parameters.color1=green5
backgr_stimulus2.parameters.color2=blue5
p.go()
p1.go()
p2.go()
p1.go()
p.go()
p1.go()
p2.go()
p1.go()
p.go()
p1.go()
p2.go()
p1.go()
p.go()
p1.go()
p2.go()
p1.go()
p.go()
p1.go()
p2.go()
p1.go()
======================================
The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html
- Follow-Ups:
- [visionegg] Re: uneven grating
- From: Andrew Straw
Other related posts:
- » [visionegg] uneven grating
- » [visionegg] Re: uneven grating
- » [visionegg] Re: uneven grating
- [visionegg] Re: uneven grating
- From: Andrew Straw