visfeats.spatial_frequency_features#
- visfeats.spatial_frequency_features(image: Image, size: int = 1024, min_frequency: float = 10.0, max_frequency: float = 256.0, log_bins: int = 17, pad: bool = True, return_spectrum: Literal[False] = False) Dict[str, float]#
- visfeats.spatial_frequency_features(image: Image, size: int = 1024, min_frequency: float = 10.0, max_frequency: float = 256.0, log_bins: int = 17, pad: bool = True, *, return_spectrum: Literal[True]) Tuple[Dict[str, float], NDArray[float64]]
Calculate features related to the spatial frequency content of an image.
- Parameters:
- image
Image Input image.
- size
int, default=1024 Square analysis resolution.
- min_frequency
float, default=10.0 Lowest radial spatial frequency to analyze, in cycles/image.
- max_frequency
float, default=256.0 Highest radial spatial frequency to analyze, in cycles/image.
- log_bins
int, default=17 Number of log-spaced frequency bins used before fitting. Redies et al. [2] used 17 bins (Figure 3a).
- padbool, default=True
Whether to pad non-square images to a square with the mean gray value before resizing, as in Redies et al. [1]. If False, the image is resized directly to
sizexsize, as in the original method [2], which distorts the aspect ratio of non-square images.- return_spectrumbool, default=False
If True, also return the radially averaged power spectrum (see Returns).
- image
- Returns:
- features
dictof {str:float} A mapping of feature names to values:
Key
Description
fourier_slopeSlope of log power versus log frequency (about -2 for natural scenes and many artworks).
fourier_deviationMean squared residual (log10 units) of the binned data around the fitted line.
dimensionalitySlope of log magnitude versus log rank of the ranked spectrum (see Notes).
spectral_centroidPower-weighted mean spatial frequency, in cycles/image.
spectral_varianceCircular variance of the power spectrum over orientation, in [0, 1] (see Notes).
- spectrum
ndarray, shape (n_frequencies, 2) Only returned when
return_spectrum=True, as the second element of a(features, spectrum)tuple. This is the radially averaged spectrum before log-binning, restricted to frequencies betweenmin_frequencyandmax_frequencywith non-zero power. Axes are:axis 0: radial frequency bin, in ascending order (one bin per cycle/image);
axis 1: column 0 = mean radial frequency of the Fourier components in the bin (cycles/image), column 1 = mean power in the bin (squared amplitude, arbitrary units).
Both columns are linear (not log-transformed). For amplitude instead of power, use
np.sqrt(spectrum[:, 1]).
- features
Notes
The function follows these steps:
Convert image to grayscale, optionally (
pad) pad to a square with the mean gray value, and resize to asizexsizesquare by bicubic interpolation [1,2]_.Compute the 2D Fourier transform and average it in annular bins of 1 cycle/image up to the Nyquist frequency, giving the mean radial frequency, mean power and mean magnitude of each annulus.
fourier_slopeandfourier_deviation: keep bins betweenmin_frequencyandmax_frequency, average log power and log frequency withinlog_binslog-spaced bins, and fit a least-squares line. The slope isfourier_slope; the mean squared residual isfourier_deviation[2].dimensionality: using the radially averaged magnitude of all bins except DC (no frequency restriction), rank the components from largest to smallest and fit a line to log magnitude versus log rank [3].spectral_centroid: using the full 2D power spectrum without DC, the mean radial frequency weighted by power (center of mass).spectral_variance: circular variance,1 - R, of the spectral orientation weighted by power, whereRis the length of the power-weighted mean resultant vector of the doubled orientation angles (the spectrum is point-symmetric). 0 means all power lies along one orientation; 1 means power is spread evenly across orientations.
[1]Redies, C., Grebenkina, M., Mohseni, M., Kaduhm, A., & Dobel, C. (2020). Global Image Properties Predict Ratings of Affective Pictures. Frontiers in Psychology, 11. https://doi.org/10.3389/fpsyg.2020.00953
[2] (1,2,3)Redies, C., Hasenstein, J., & Denzler, J. (2007). Fractal-like image statistics in visual art: Similarity to natural scenes. Spatial Vision, 21(1–2), 137–148. https://doi.org/10.1163/156856807782753921
[3]Uran, C., Peter, A., Lazar, A., Barnes, W., Klon-Lipok, J., Shapcott, K. A., Roese, R., Fries, P., Singer, W., & Vinck, M. (2022). Predictive coding of natural images by V1 firing rates and rhythmic synchronization. Neuron, 110(7), 1240-1257.e8. https://doi.org/10.1016/j.neuron.2022.01.002