psychos.visual.synthetic.gabor_3d#
- psychos.visual.synthetic.gabor_3d(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[[ndarray], ndarray] | Tuple[str | Tuple[int, int, int] | Tuple[int, int, int, int] | Tuple[float, float, float] | Tuple[float, float, float, float], str | Tuple[int, int, int] | Tuple[int, int, int, int] | Tuple[float, float, float] | Tuple[float, float, float, float]] | list = ('black', 'white'), alpha_channel: Literal['envelope'] | None | ndarray = 'envelope', **kwargs) ndarray[source]#
Generate a 3D (color) Gabor patch as a numpy array by mapping a grayscale 2D Gabor (computed via gabor_2d) into RGB values using a colormap. An optional alpha channel may be included.
- Parameters:
size (Tuple[int, int]) – (height, width) of the output image in pixels.
spatial_frequency (float) – Cycles per entire image width.
orientation (float) – Gabor orientation in degrees, [0..360].
phase (float) – Fraction of 2*pi for the carrier phase, in [0..1].
sigma (Optional[float]) – Standard deviation of the Gaussian envelope as a fraction of the minimum dimension. If None, no envelope is applied (envelope defaults to ones).
gamma (float) – Aspect ratio of the Gaussian envelope.
contrast (float) – Contrast (amplitude) of the sinusoidal carrier.
center (Optional[Tuple[float, float]]) – Center (y, x) in pixel coordinates. Defaults to image center if None.
cmap (Union[str, Callable[[np.ndarray], np.ndarray], Tuple[ColorType, ColorType], list]) – Colormap used to map normalized grayscale values 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.
alpha_channel (Union[Literal["envelope"], None, np.ndarray]) –
- Determines the alpha channel:
”envelope”: use the Gaussian envelope computed in gabor_2d.
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 passed to gabor_2d (e.g., baseline, rescale).
- Returns:
If an alpha channel is provided, returns an RGBA image (height x width x 4); otherwise, returns an RGB image (height x width x 3).
- Return type:
np.ndarray
Example
>>> import matplotlib.pyplot as plt >>> # Using a matplotlib colormap: >>> gabor_color = gabor_3d(size=(256, 256), spatial_frequency=2.0, orientation=45.0, ... phase=0.25, sigma=0.25, gamma=1.0, contrast=1.0, ... cmap='viridis', alpha_channel="envelope", ... baseline=0.0, rescale='normalize', vmin=0.0, vmax=1.0) >>> plt.imshow(gabor_color, origin='lower') >>> plt.title("3D Gabor Patch with Envelope as Alpha") >>> plt.show() >>> # Using two-color interpolation: >>> gabor_color2 = gabor_3d(size=(256, 256), spatial_frequency=2.0, orientation=45.0, ... phase=0.25, sigma=0.25, gamma=1.0, contrast=1.0, ... cmap=('black', 'white'), alpha_channel="envelope") >>> plt.imshow(gabor_color2, origin='lower') >>> plt.title("3D Gabor Patch (Black-to-White)") >>> plt.show()