# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
# %matplotlib inline
import matplotlib.pyplot as plt
import math
import numpy as np
from skimage.draw import (line, polygon, circle,
                          circle_perimeter,
                          ellipse, ellipse_perimeter,
                          bezier_curve)

img = np.zeros((512, 512, 3), dtype=np.double)

rr, cc = line(125, 125, 10, 300)
img[rr, cc, 1] = 1

poly = np.array((
    (300, 300),
    (480, 320),
    (380, 430),
    (220, 590),
    (300, 300),
))
rr, cc = polygon(poly[:, 0], poly[:, 1], img.shape)
img[rr, cc, 1] = 1

rr, cc = circle(250, 250, 50, img.shape)
img[rr, cc, :] = (1, 1, 0)

rr, cc = ellipse(300, 300, 150, 200, img.shape)
img[rr, cc, 2] = 1

rr, cc = circle_perimeter(200, 300, 15)
img[rr, cc, :] = (0.5, 0, 0)

rr, cc = bezier_curve(70, 100, 10, 10, 150, 100, 1)
img[rr, cc, :] = (1, 0, 0)

rr, cc = ellipse_perimeter(120, 400, 60, 20, orientation=math.pi / 4.)
img[rr, cc, :] = (1, 0, 1)

rr, cc = ellipse_perimeter(120, 400, 60, 20, orientation=-math.pi / 4.)
img[rr, cc, :] = (0, 0, 1)

rr, cc = ellipse_perimeter(120, 400, 60, 20, orientation=math.pi / 2.)
img[rr, cc, :] = (1, 1, 1)

plt.imshow(img)
plt.title('Shapes')
plt.xticks([])
plt.yticks([])
plt.show()

# +
from skimage.draw import line_aa, circle_perimeter_aa

img = np.zeros((512, 512, 3), dtype=np.double)

rr, cc, val = line_aa(12, 12, 220, 250)
img[rr, cc, :] = [1, 1, 1]

rr, cc, val = circle_perimeter_aa(90, 90, 60)
img[rr, cc, :] = [1, 1, 1]

plt.imshow(img)
plt.title('Shapes')
plt.xticks([])
plt.yticks([])
plt.show()

# +
from skimage.draw import random_shapes

image0, _ = random_shapes((128, 128), max_shapes=1, shape='rectangle',
                       multichannel=False)

image1, _ = random_shapes((128, 128), max_shapes=1, shape='circle')

image2, _ = random_shapes((128, 128), max_shapes=10,
                          intensity_range=((100, 255),))

image3, _ = random_shapes((128, 128), min_shapes=5, max_shapes=10,
                         min_size=20, allow_overlap=True)


images = [image0, image1, image2, image3]

for i in range(4):
    plt.subplot(2, 2, i+1)
    if i == 0:
        plt.imshow(images[i], cmap='gray')
    else:
        plt.imshow(images[i])

plt.show()

StarcoderdataJupyterScriptsDedupFiltered