ellipse
A parametrized dataset of pictures of ellipses, for Neural Network experimentation.
from ellipse import *
import matplotlib.pyplot as plt
%matplotlib inline
This example reminds us how the plots are oriented, which is not the usual math way.
A = np.array([[1,2],[3,4]])
print(A)
plt.imshow(A, cmap='Blues')
plt.colorbar()
plt.show()
[[1 2]
[3 4]]
Basic options
Let's see the basic parameters
plt.imshow(get_ellipse())
plt.show()
Change the position
plt.imshow(get_ellipse(row=40, col=10))
plt.show()
Change the radii
plt.imshow(get_ellipse(a=20, b=5))
plt.show()
Change the angle. Note that the image row,col coordinate system is still right-handed, so rotation turns anticlockwise as normal.
plt.imshow(get_ellipse(a=20, b=5, theta=np.pi/12))
plt.show()
We can combine all the options
plt.imshow(get_ellipse(row=48, col=16, a=16, b=2, theta=np.pi/6))
plt.show()
Advanced Options
We can adjust the downsampling to make a smoother or coarser edge. The default is 4. For illustration, here is the edge effect of the downsampling
fig,ax = plt.subplots(1,3, figsize=(6,18),dpi=100)
ax[0].imshow(get_ellipse(a=20, downsample_factor=1))
ax[0].set_title("factor 1")
ax[0].set_aspect(1.0)
ax[1].imshow(get_ellipse(a=20, downsample_factor=10))
ax[1].set_title("factor 10")
ax[1].set_aspect(1.0)
ax[2].imshow(get_ellipse(a=20, downsample_factor=10) - get_ellipse(a=20, downsample_factor=1))
ax[2].set_title("difference")
ax[2].set_aspect(1.0)
fig.tight_layout()
plt.show()
The coordinate system wraps around, so the ellipse is really drawn on a torus.
plt.imshow(get_ellipse(img_size=64, row=56, col=16, a=16, b=2, theta=np.pi/6, downsample_factor=4))
plt.show()
We can change the canvas size, but note that you will want to adjust the centers and radii, which chosen to reasonable values for a 64x64 canvas
plt.imshow(get_ellipse(img_size=8, row=5, col=3, a=3, b=1, theta=np.pi/6, downsample_factor=1))
plt.show()
plt.imshow(get_ellipse(img_size=256, row=160, col=96, a=96, b=32, theta=np.pi/6, downsample_factor=1))
plt.show()
Sometimes, we do not want to allow that wrap-around. The check_bounds function is used by allow_wrap=False.
See the check_bounds.ipynb notebook for more use of boundschecking.
check_bounds(img_size=64, row=56, col=16, a=16, b=2, theta=np.pi/6, downsample_factor=4)
False
check_bounds(img_size=64, row=47, col=16, a=16, b=2, theta=np.pi/6, downsample_factor=4)
True
Generating Random Examples
We can generate random examples and feed their parameters to get_ellipse
p = generate(64, row_range=(0,64), col_range=(0,64), area_range=(8*np.pi,16*np.pi), logar_range=(1,2), theta_range=(0,np.pi))
plt.imshow(get_ellipse(**p))
plt.title(f"bounds? {check_bounds(**p)}")
plt.show()
fig,axs = plt.subplots(1,8, figsize=(4*8,4))
for i in range(8):
p = generate(64, row_range=(0,64), col_range=(0,64), area_range=(8*np.pi,16*np.pi), logar_range=(1,2), theta_range=(0,np.pi))
E = get_ellipse(**p, downsample_factor=3)
axs[i].imshow(E)
plt.show()
Pre-defined datasets
Some datasets are particularly useful for our experiements. We have hard-coded their parameterizations.
from ellipse.datasets import torus
X = torus(n=100,return_arrays=True)
fig,ax = plt.subplots(10,10, figsize=(20,20))
for i in range(100):
ax[i//10,i%10].imshow(X[i])
plt.show()
import ellipse
help(ellipse.get_ellipse)
Help on function get_ellipse in module ellipse:
get_ellipse(img_size: int = 64, row: int = 32, col: int = 32, a: float = 16, b: float = 16, theta: float = 0.0, downsample_factor: int = 4, allow_wrap=True)
Make a single ellipse with the given geometry.
NOTE! We use the "upper-left" origin convention, so that plt.imgshow( ) and print( )
give the same orientation of the image/matrix.
:param img_size: Output image resolution. For example, 64 gives a 64x64 image.
:param r: row-position of ellipse center. Relative to upper-left of image.
:param c: col-position of ellipse center. Relative to upper-left of image.
:param a: Length of semi-major axis.
:param b: Length of semi-minor axis.
:param theta: Angle in radians of the semi-major axis versus the row-axis, in range [0,pi]
:param downsample_factor: Oversampling factor for downscaling image. Default=4.
:param allow_wrap: If False, raise an exception if the ellipse wraps around the image.
:return: numpy array of shape (img_size,img_size) suitable for `matplotlib.pyplot.imshow`
Metadata
Release files for ellipse 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ellipse-0.6.0.tar.gz | 5.6 kB | Without provenance | Details for ellipse-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ellipse-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for ellipse-0.6.0-py3-none-any.whl |
Total release size: 11.6 kB
Release files / ellipse-0.6.0.tar.gz
| Download URL | ellipse-0.6.0.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
55424c426bf1364f884506362596b22122387cd15ef21eba3256335a2f5d73ec
|
|
BLAKE2b-256 checksum How to use checksums |
f16121629a9f8a518921b40546fefa13cfd68b1a86b083c58e7d4a8b59b54839
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.5
|
Release files / ellipse-0.6.0-py3-none-any.whl
| Download URL | ellipse-0.6.0-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c0510d4b7829b0d2ef78963b1a66d563a02c2bfc1c5dc7a157c5f45add13525c
|
|
BLAKE2b-256 checksum How to use checksums |
2d96eb292e96a7cba26557631da74a0b8be02fa50eb3ea1bc86ffb0858bf28c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.5
|
Security for ellipse 0.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.