stnmf.spatial.ellipse
- stnmf.spatial.ellipse(image, sigma=2.0)
Fit a two-dimensional Gaussian to an image and return a parameterized ellipse
- Parameters:
image (
(x,y)or(r,x,y) array_like) – Two-dimensional image or stack of r independent two-dimensional images, where x and y are the spatial dimensionssigma (
float, optional) – Standard deviations (s.d.) of the mean (Mahalanobis distance) for the ellipse boundary. 2 s.d. are best suited for analysis of receptive fields of retinal ganglion cells [1]. Default is 2.0
- Returns:
(mux, muy, r_major, r_minor, rad) (
tupleoffloat,(r,5) np.ndarray) – Parameterized ellipse, where mux and muy are the centroid, r_major and r_minor are the semi-major and semi-minor axes, that is, major and minor radii, and rad is the rotation in radians. Or stack of r parameterized ellipses in an (r, 5) float array- Raises:
IndexError – If image is not two-dimensional.
ValueError – If sigma is smaller or equal zero.
Examples
The parameterized ellipse offers a compressed representation of the ellipse. For example, it is useful for calculating the effective diameter of a receptive field.
>>> p = ellipse(spatial_filter) >>> pixel_size = 30 # Conversion to micrometers >>> a, b = p[2:4] # Major and minor axes radii >>> rf_diameter = 2 * np.sqrt(a*b) * pixel_size
To obtain an outline of the ellipse in data coordinates:
>>> mux, muy, r_major, r_minor, rad = ellipse(spatial_filter) >>> num_points = 200 >>> ls = np.linspace(0, 2*np.pi, num_points)
>>> rot = [[np.cos(rad), -np.sin(rad)], [np.sin(rad), np.cos(rad)]] >>> pos = [r_major * np.cos(ls), r_minor * np.sin(ls)] >>> points = np.dot(rot, pos) + [[mux], [muy]]
References