psychos.visual.Gabor#
- class psychos.visual.Gabor(size: Tuple[int, int] = (256, 256), spatial_frequency: float = 8.0, orientation: float = 45.0, phase: float = 0.0, sigma: float | None = 0.15, gamma: float = 1.0, contrast: float = 1.0, center: Tuple[float, float] | None = None, cmap: str | Callable[[np.ndarray], np.ndarray] | Tuple[ColorType, ColorType] | list = ('black', 'white'), alpha_channel: Literal['envelope'] | None | np.ndarray = 'envelope', gabor_kwargs={}, image_path: str | None = None, position: Tuple[float, float] = (0, 0), width: float | None = None, height: float | None = None, scale: float | None = None, rotation: float = 0, anchor_x: str = 'center', anchor_y: str = 'center', window: Window | None = None, coordinates: UnitType | Unit | None = None, **sprite_kwargs)[source]#
Bases:
RawImageA Gabor stimulus for psychophysical experiments.
This class generates a synthetic Gabor patch using a 3D (color) Gabor generator and displays it in a Pyglet window via the RawImage (Sprite) component. It combines the parameters for generating the Gabor stimulus with those for positioning, scaling, and rotating the image.
- Parameters:
parameters (# RawImage)
size (Tuple[int, int], default=(128, 128)) – The (height, width) of the generated image in pixels.
spatial_frequency (float, default=5.0) – Cycles per entire image width.
orientation (float, default=45.0) – Gabor orientation in degrees [0, 360]. The carrier is rotated by (360 - orientation) degrees.
phase (float, default=0.0) – Fraction of 2π for the carrier phase, in the range [0, 1].
sigma (Optional[float], default=0.15) – Normalized standard deviation (fraction of the minimum dimension) of the Gaussian envelope. If None, no envelope is applied (i.e. the envelope defaults to ones).
gamma (float, default=1.0) – Aspect ratio (vertical stretch) of the Gaussian envelope.
contrast (float, default=1.0) – Contrast (amplitude) of the sinusoidal carrier.
center (Optional[Tuple[float, float]], default=None) – Center (y, x) of the Gabor patch in pixel coordinates. Defaults to the image center if None.
cmap (Union[str, Callable[[np.ndarray], np.ndarray], Tuple[ColorType, ColorType], list], default=("black", "white")) – Colormap used to map the normalized grayscale Gabor to colors. If a string, it must be a valid matplotlib colormap name. Alternatively, a callable mapping an array in [0,1] to an RGBA image, or a tuple/list of two colors (low and high) for linear two-color interpolation (colors are parsed via Color().to_rgb()).
alpha_channel (Union[Literal["envelope"], None, np.ndarray], default="envelope") –
- Determines the alpha channel:
”envelope”: use the Gaussian envelope computed in gabor_3d.
None: do not include an alpha channel (output will be RGB).
A numpy array: must have the same shape as the 2D gabor; used as the alpha channel.
**kwargs – Additional keyword arguments to be passed to the gabor_3d function.
parameters
image_path (Optional[str]) – The path to the image file. (Not used here since the image is generated synthetically.)
position (Tuple[float, float], default=(0, 0)) – The position of the image in the window.
width (Optional[float], default=None) – The target width to scale the image to.
height (Optional[float], default=None) – The target height to scale the image to.
scale (Optional[float], default=None) – A uniform scaling factor for the image.
rotation (float, default=0) – The rotation angle of the image in degrees.
anchor_x (str, default="center") – The horizontal anchor alignment for the image.
anchor_y (str, default="center") – The vertical anchor alignment for the image.
window (Optional[Window], default=None) – The window in which the image will be displayed.
coordinates (Optional[Union[UnitType, Units]], default=None) – The coordinate system to use for positioning the image.
(additional) (**kwargs) – Additional keyword arguments are passed to the underlying Pyglet Sprite class.
- Inherits all attributes from RawImage, such as position, rotation, scale, etc.
Example
>>> from synthetic_stim import Gabor # or your module name >>> # Create a Gabor stimulus with a viridis colormap and envelope as the alpha channel. >>> gabor = Gabor( ... size=(256, 256), ... spatial_frequency=2.0, ... orientation=45.0, ... phase=0.25, ... sigma=0.25, ... gamma=1.0, ... contrast=1.0, ... center=(128, 128), ... cmap='viridis', ... alpha_channel="envelope", ... position=(100, 150), ... width=300, ... rotation=30 ... ) >>> gabor.draw()
- __init__(size: Tuple[int, int] = (256, 256), spatial_frequency: float = 8.0, orientation: float = 45.0, phase: float = 0.0, sigma: float | None = 0.15, gamma: float = 1.0, contrast: float = 1.0, center: Tuple[float, float] | None = None, cmap: str | Callable[[np.ndarray], np.ndarray] | Tuple[ColorType, ColorType] | list = ('black', 'white'), alpha_channel: Literal['envelope'] | None | np.ndarray = 'envelope', gabor_kwargs={}, image_path: str | None = None, position: Tuple[float, float] = (0, 0), width: float | None = None, height: float | None = None, scale: float | None = None, rotation: float = 0, anchor_x: str = 'center', anchor_y: str = 'center', window: Window | None = None, coordinates: UnitType | Unit | None = None, **sprite_kwargs)[source]#
Create a Sprite instance.
- Parameters:
img – Image or Animation to display.
x – X coordinate of the sprite.
y – Y coordinate of the sprite.
z – Z coordinate of the sprite.
blend_src – OpenGL blend source mode. The default is suitable for compositing sprites drawn from back-to-front.
blend_dest – OpenGL blend destination mode. The default is suitable for compositing sprites drawn from back-to-front.
batch – Optional batch to add the sprite to.
group – Optional parent group of the sprite.
subpixel – Allow floating-point coordinates for the sprite. By default, coordinates are restricted to integer values.
program – A specific shader program to initialize the sprite with. By default, a pre-made shader will be chosen based on the texture type passed.
Added in version 2.0.16: The program parameter.
Methods
__init__([size, spatial_frequency, ...])Create a Sprite instance.
delete()Force immediate removal of the sprite from video memory.
dispatch_event(event_type, *args)Dispatch an event to the attached event handlers.
draw()Draw the sprite at its current position.
event(*args)Function decorator for an event handler.
get_sprite_group()Creates and returns a group to be used to render the sprite.
parse_image(raw_image)pop_handlers()Pop the top level of event handlers off the stack.
post_event(event_type, *args)Post an event to the main application thread.
push_handlers(*args, **kwargs)Push a new level onto the handler stack, and add 0 or more handlers.
register_event_type(name)Register an event type with the dispatcher.
remove_handler(name, handler)Remove a single event handler.
remove_handlers(*args, **kwargs)Remove event handlers from the event stack.
set_handler(name, handler)Attach a single event handler.
set_handlers(*args, **kwargs)Attach one or more event handlers to the top level of the handler stack.
update([x, y, z, rotation, scale, scale_x, ...])Simultaneously change the position, rotation or scale.
Attributes
batchGraphics batch.
blend_modeThe current blend mode applied to this sprite.
colorBlend color.
coordinatesGet the coordinate system used for the text.
event_typesframe_indexThe current Animation frame.
groupParent graphics group specified by the user.
heightScaled height of the sprite.
imageThe Sprite's Image or Animation to display.
opacityBlend opacity.
pausedPause/resume the Sprite's Animation.
positionGet the position of the image.
programThe current shader program.
rotationClockwise rotation of the sprite, in degrees.
scaleBase Scaling factor.
scale_xHorizontal scaling factor.
scale_yVertical scaling factor.
visibleTrue if the sprite will be drawn.
widthScaled width of the sprite.
xX coordinate of the sprite.
yY coordinate of the sprite.
zZ coordinate of the sprite.