本文整理汇总了Python中skimage.draw.ellipse函数的典型用法代码示例。如果您正苦于以下问题:Python ellipse函数的具体用法?Python ellipse怎么用?Python ellipse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ellipse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ellipse_trivial
def test_ellipse_trivial():
img = np.zeros((2, 2), "uint8")
rr, cc = ellipse(0.5, 0.5, 0.5, 0.5)
img[rr, cc] = 1
img_correct = np.array([[0, 0], [0, 0]])
assert_array_equal(img, img_correct)
img = np.zeros((2, 2), "uint8")
rr, cc = ellipse(0.5, 0.5, 1.1, 1.1)
img[rr, cc] = 1
img_correct = np.array([[1, 1], [1, 1]])
assert_array_equal(img, img_correct)
img = np.zeros((3, 3), "uint8")
rr, cc = ellipse(1, 1, 0.9, 0.9)
img[rr, cc] = 1
img_correct = np.array([[0, 0, 0], [0, 1, 0], [0, 0, 0]])
assert_array_equal(img, img_correct)
img = np.zeros((3, 3), "uint8")
rr, cc = ellipse(1, 1, 1.1, 1.1)
img[rr, cc] = 1
img_correct = np.array([[0, 1, 0], [1, 1, 1], [0, 1, 0]])
assert_array_equal(img, img_correct)
img = np.zeros((3, 3), "uint8")
rr, cc = ellipse(1, 1, 1.5, 1.5)
img[rr, cc] = 1
img_correct = np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]])
assert_array_equal(img, img_correct)
示例2: test_ellipse_rotation_symmetry
def test_ellipse_rotation_symmetry():
img1 = np.zeros((150, 150), dtype=np.uint8)
img2 = np.zeros((150, 150), dtype=np.uint8)
for angle in range(0, 180, 15):
img1.fill(0)
rr, cc = ellipse(80, 70, 60, 40, rotation=np.deg2rad(angle))
img1[rr, cc] = 1
img2.fill(0)
rr, cc = ellipse(80, 70, 60, 40, rotation=np.deg2rad(angle + 180))
img2[rr, cc] = 1
assert_array_equal(img1, img2)
示例3: add_Ellipse
def add_Ellipse(self, scale = 1, thick = 5):
"""h for vertical, w for horizontal"""
h = self.e_h = self.base_e_h * scale
w = self.e_w = self.base_e_w * scale
# e and lv should not be too close
shift = self.e_w/8
center = self.lv_center + self.lv_radius_vec
center[1] += shift
self.e_center = center
self.e_thick = thick
self.e_big = d.ellipse(center[0], center[1], h, w)
self.e_small= d.ellipse(center[0], center[1], h-thick, w-thick)
示例4: test_ellipse
def test_ellipse():
img = np.zeros((15, 15), 'uint8')
rr, cc = ellipse(7, 7, 3, 7)
img[rr, cc] = 1
img_ = np.array(
[[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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0, 0, 0]]
)
assert_array_equal(img, img_)
示例5: test_ellipse_with_shape
def test_ellipse_with_shape():
img = np.zeros((15, 15), 'uint8')
rr, cc = ellipse(7, 7, 3, 10, shape=img.shape)
img[rr, cc] = 1
img_ = np.array(
[[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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0]]
)
assert_array_equal(img, img_)
示例6: makeFakeVessels
def makeFakeVessels(imgsize=(512, 512), background=230):
"""
create and save a matrix with whitish background and randomly selected vessel sizes and save matrices generated as images of format png
"""
nVes = 20
mu = 20
sigma = 5
minw = 5
sx, sy = imgsize
vasc = np.ones((sx, sy), dtype=np.uint8) * background
for i in range(nVes):
cx, cy = random.uniform(0, sx), random.uniform(0, sy)
r1, r2 = 0, 0
while (r1 < minw) or (r2 < minw):
np.random.seed(20)
r1 = np.random.normal(mu, sigma)
r2 = np.random.normal(mu, sigma)
print(r1, r2)
rr, cc = ellipse(cy, cx, r1, r2)
if np.any(rr >= sy):
ix = rr < sy
rr, cc = rr[ix], cc[ix]
if np.any(cc >= sx):
ix = cc < sx
rr, cc = rr[ix], cc[ix]
vasc[rr, cc] = 1 # make circle blackish
return vasc
示例7: test_ellipse_negative
def test_ellipse_negative():
rr, cc = ellipse(-3, -3, 1.7, 1.7)
rr_, cc_ = np.nonzero(
np.array([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]])
)
assert_array_equal(rr, rr_ - 5)
assert_array_equal(cc, cc_ - 5)
示例8: setup
def setup():
image = np.zeros((30, 30, 3), dtype=float)
image[draw.ellipse(15, 15, 5, 8)] = 1
state = np.zeros((30, 30, 2))
state[15, 15] = (1, 1)
state[0, 0] = (0, 1)
return image, state
示例9: get_indices
def get_indices(self):
"""Returns a set of points that lie inside the picked polygon."""
if not self.center:
raise ValueError("Cannot get ellipse indices before the dimensions are defined")
x, y = self.center
w = self.width
h = self.height
return ellipse(y, x, h/2., w/2., self.im)
示例10: test_ellipse_rotated
def test_ellipse_rotated():
img = np.zeros((1000, 1200), dtype=np.uint8)
for rot in range(0, 180, 10):
img.fill(0)
angle = np.deg2rad(rot)
rr, cc = ellipse(500, 600, 200, 400, rotation=angle)
img[rr, cc] = 1
# estimate orientation of ellipse
angle_estim = np.round(regionprops(img)[0].orientation, 3) % (np.pi / 2)
assert_almost_equal(angle_estim, angle % (np.pi / 2), 2)
示例11: test_rotate_largest_region
def test_rotate_largest_region(self):
test_img = np.zeros((1000,1000), dtype=np.uint8)
rr, cc = circle(100,100,50)
test_img[rr,cc] = 1
rr, cc = ellipse(500,500,300,100)
test_img[rr, cc] = 1
rotated = gzapi.rotate_largest_region(test_img)
largest_region = gzapi.get_largest_region(rotated)
self.assertAlmostEqual(largest_region.orientation, 0)
self.assertIsNone(gzapi.rotate_largest_region(None))
示例12: sim_wire
def sim_wire(angle, gaussian_sigma=1, noise_level=0, L=100):
"Draw a wire with blur and optional noise."
# Noise level should be from 0 to 1. 0.02 is reasonable.
shape = (L, L)
a = np.zeros(shape, dtype=np.uint8)
a[draw.ellipse(L//2, L//2, L//24, L//4)] = 100 # horizontal ellipse
a = filter.gaussian_filter(a, gaussian_sigma)
b = transform.rotate(a, angle)
b += noise_level*np.random.randn(*shape)
return b
示例13: _measure_fluorescence
def _measure_fluorescence(self, time_period, time_index, image_slice, channel_annotation):
mask = np.zeros((image_slice.height * 2, image_slice.width))
old_pole, new_pole = channel_annotation.get_cell_bounds(time_period, time_index)
ellipse_minor_radius = int(0.80 * image_slice.height)
ellipse_major_radius = int((new_pole - old_pole) / 2.0) * 0.8
centroid_y = int(image_slice.height)
centroid_x = int((new_pole + old_pole) / 2.0)
rr, cc = draw.ellipse(centroid_y, centroid_x, ellipse_minor_radius, ellipse_major_radius)
mask[rr, cc] = 1
mean, stddev, median, area, centroid = self._calculate_cell_intensity_statistics(mask.astype("int"), image_slice.image_data)
return mean, stddev, median, area, centroid
示例14: test_growcut_basic
def test_growcut_basic():
image = np.zeros((30, 30, 3), dtype=float)
image[draw.ellipse(15, 15, 5, 8)] = 1
state = np.zeros((30, 30, 2))
state[15, 15] = (1, 1)
state[0, 0] = (0, 1)
npt.assert_array_equal(image[..., 0],
growcut(image, state, window_size=3, max_iter=20))
npt.assert_array_equal(image[..., 0],
growcut_fast(image, state, window_size=3, max_iter=20))
示例15: ellipse
def ellipse(width, height, dtype=np.uint8):
"""Generates a flat, ellipse-shaped structuring element.
Every pixel along the perimeter of ellipse satisfies
the equation ``(x/width+1)**2 + (y/height+1)**2 = 1``.
Parameters
----------
width : int
The width of the ellipse-shaped structuring element.
height : int
The height of the ellipse-shaped structuring element.
Other Parameters
----------------
dtype : data-type
The data type of the structuring element.
Returns
-------
selem : ndarray
The structuring element where elements of the neighborhood
are 1 and 0 otherwise.
Examples
--------
>>> from skimage.morphology import selem
>>> selem.ellipse(5, 3)
array([[0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0]], dtype=uint8)
"""
selem = np.zeros((2 * height + 1, 2 * width + 1), dtype=dtype)
rows, cols = draw.ellipse(height, width, height + 1, width + 1)
selem[rows, cols] = 1
return selem