Skip to main content

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]]

png

Basic options

Let's see the basic parameters

plt.imshow(get_ellipse())
plt.show()

png

Change the position

plt.imshow(get_ellipse(row=40, col=10))
plt.show()

png

Change the radii

plt.imshow(get_ellipse(a=20, b=5))
plt.show()

png

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()

png

We can combine all the options

plt.imshow(get_ellipse(row=48, col=16, a=16, b=2, theta=np.pi/6))
plt.show()

png

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()

png

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()

png

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()

png

plt.imshow(get_ellipse(img_size=256, row=160, col=96, a=96, b=32, theta=np.pi/6, downsample_factor=1))
plt.show()

png

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()

png

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()

png

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()

png

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`

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ellipse-0.6.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ellipse-0.6.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file ellipse-0.6.0.tar.gz.

File metadata

  • Download URL: ellipse-0.6.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for ellipse-0.6.0.tar.gz
Algorithm Hash digest
SHA256 55424c426bf1364f884506362596b22122387cd15ef21eba3256335a2f5d73ec
MD5 b6d652e4b6e92934b951df9b26175740
BLAKE2b-256 f16121629a9f8a518921b40546fefa13cfd68b1a86b083c58e7d4a8b59b54839

See more details on using hashes here.

File details

Details for the file ellipse-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: ellipse-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for ellipse-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0510d4b7829b0d2ef78963b1a66d563a02c2bfc1c5dc7a157c5f45add13525c
MD5 2ba10b2590d33a4752f813381fa91986
BLAKE2b-256 2d96eb292e96a7cba26557631da74a0b8be02fa50eb3ea1bc86ffb0858bf28c1

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 files

0.5.5

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page