<jupyter_start><jupyter_text>Function ellipse SynopseCreate a binary ellipse image.- **g = ellipse(s, r, c, theta)**  - Output:      - **g**: Image.  - Input:      - **s**: Image. [rows cols], output image dimensions.      - **r**: Double. [rRows rCols], radius for y and x directions.      - **c**: Image. [row0 col0], center of the circle.      - **theta**: Double. Angle rotation in radians. (optional)  DescriptionThe $ellipse$ function creates a binary image with dimensions given by $s$, radius given by $r (r[0] = rRows; r[1] = rCols)$ and center given by $c$. The pixels inside the circle are one and outside zero.  Function code<jupyter_code>import numpy as np
 
def ellipse(s, r, c, theta=0):
    rows, cols = s[0], s[1]
    rr0,  cc0  = c[0], c[1]
    rr, cc = np.meshgrid(range(rows), range(cols), indexing='ij')
    rr = rr - rr0
    cc = cc - cc0
    cos = np.cos(theta)
    sen = np.sin(theta)
    i = cos/r[1]
    j = sen/r[0]
    m = -sen/r[1]
    n = cos/r[0]
    g = ((i*cc + m*rr)**2 + (j*cc + n*rr)**2) <= 1
    return g
testing = (__name__ == "__main__")

if testing:
    ! jupyter nbconvert --to python ellipse.ipynb
    import numpy as np
    import sys,os
    import matplotlib.image as mpimg
    ia898path = os.path.abspath('../../')
    if ia898path not in sys.path:
        sys.path.append(ia898path)
    import ia898.src as ia<jupyter_output>[NbConvertApp] Converting notebook ellipse.ipynb to python
[NbConvertApp] Writing 2389 bytes to ellipse.py<jupyter_text>Examples Numerical example:<jupyter_code>if testing:
    g = ia.ellipse([16,16], [2,4], [8,8], np.pi * 0.25)
    print('g:\n', g.astype(int))<jupyter_output>g:
 [[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0]
 [0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0]
 [0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0]
 [0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0]
 [0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0]
 [0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0]
 [0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
 [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]<jupyter_text>Measuring time:<jupyter_code>if testing:
    from time import time
    t = time()
    g = ia.ellipse([300,300], [90,140], [150,150], np.pi * 0.25)
    tend = time()
    print('Computational time (10k, 10k) is {0:.2f} seconds.'.format(tend - t))
    ia.adshow(g, "Ellipse")
if testing:
    print('Computational time (10k, 10k) is:')
    %timeit ia.ellipse([300,300], [90,140], [150,150], np.pi * 0.25)<jupyter_output>Computational time (10k, 10k) is:
100 loops, best of 3: 1.72 ms per loop
{'fraction_non_alphanumeric': 0.1400147383935151, 'fraction_numerical': 0.13411938098747236, 'mean_word_length': 2.494208494208494, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '333338', 'license': 'MIT', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1134, 'n_words': 494, 'path': 'src/ellipse.ipynb', 'repo_name': 'jamfeitosa/ia898', 'size': '2714'}