本文整理匯總了Python中skimage.draw.circle方法的典型用法代碼示例。如果您正苦於以下問題:Python draw.circle方法的具體用法?Python draw.circle怎麽用?Python draw.circle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類skimage.draw
的用法示例。
在下文中一共展示了draw.circle方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: visualize
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import circle [as 別名]
def visualize(folder, imagenames, mesh_2d, joints_2d):
i = 0
for name, mesh, joints in zip(imagenames, mesh_2d, joints_2d):
shutil.copyfile(name,
'/im_gt_{}.png'.format(folder, i)
)
im = imread(name)
shape = im.shape[0:2]
height = im.shape[0]
for p2d in mesh:
im[height - p2d[1], p2d[0]] = [127,127,127]
for j2d in joints:
rr, cc = circle(height - j2d[1], j2d[0], 2, shape)
im[rr, cc] = [255, 0, 0]
imsave('{}/im_mask_{}.png'.format(folder, i), im)
i += 1
示例2: draw_pose_from_cords
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import circle [as 別名]
def draw_pose_from_cords(pose_joints, img_size, radius=2, draw_joints=True):
colors = np.zeros(shape=img_size + (3,), dtype=np.uint8)
mask = np.zeros(shape=img_size, dtype=bool)
if draw_joints:
for f, t in LIMB_SEQ:
from_missing = pose_joints[f][0] == MISSING_VALUE or pose_joints[f][1] == MISSING_VALUE
to_missing = pose_joints[t][0] == MISSING_VALUE or pose_joints[t][1] == MISSING_VALUE
if from_missing or to_missing:
continue
yy, xx, val = line_aa(pose_joints[f][0], pose_joints[f][1], pose_joints[t][0], pose_joints[t][1])
colors[yy, xx] = np.expand_dims(val, 1) * 255
mask[yy, xx] = True
for i, joint in enumerate(pose_joints):
if pose_joints[i][0] == MISSING_VALUE or pose_joints[i][1] == MISSING_VALUE:
continue
yy, xx = circle(joint[0], joint[1], radius=radius, shape=img_size)
colors[yy, xx] = COLORS[i]
mask[yy, xx] = True
return colors, mask
示例3: process_failure
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import circle [as 別名]
def process_failure(name):
name = name.replace("mask","truth")
name2 = name.replace("truth","")
image,_,_ = image_read_write.load_itk_image(name2)
#image_cropped = image[:,120:420,60:460]
image_mask = np.zeros(image.shape)
center = 256
cc,rr = circle(center+20,center,160)
image_mask[:,cc,rr] = 1
image[image>threshold]=0
image[image!=0]=1
image = image*image_mask
#image_cropped[image_cropped>threshold]=0
#image_cropped[image_cropped!=0]=1
kernel20 = np.zeros((15,15))
cc,rr = circle(7,7,8)
kernel20[cc,rr]=1
image = binary_closing(image, [kernel20],1)
#image[:,:,:]=0
#image[:,120:420,60:460]=image_cropped
truth,_,_ = image_read_write.load_itk_image(name)
print evaluator.calculate_dice(image,truth,name)
image = np.array(image,dtype=np.int8)
#LoadImages.save_itk(image,name)
示例4: draw_pose_from_cords
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import circle [as 別名]
def draw_pose_from_cords(pose_joints, img_size, radius=2, draw_joints=True):
colors = np.zeros(shape=img_size + (3, ), dtype=np.uint8)
mask = np.zeros(shape=img_size, dtype=bool)
if draw_joints:
for f, t in LIMB_SEQ:
from_missing = pose_joints[f][0] == MISSING_VALUE or pose_joints[f][1] == MISSING_VALUE
to_missing = pose_joints[t][0] == MISSING_VALUE or pose_joints[t][1] == MISSING_VALUE
if from_missing or to_missing:
continue
yy, xx, val = line_aa(pose_joints[f][0], pose_joints[f][1], pose_joints[t][0], pose_joints[t][1])
colors[yy, xx] = np.expand_dims(val, 1) * 255
mask[yy, xx] = True
for i, joint in enumerate(pose_joints):
if pose_joints[i][0] == MISSING_VALUE or pose_joints[i][1] == MISSING_VALUE:
continue
yy, xx = circle(joint[0], joint[1], radius=radius, shape=img_size)
colors[yy, xx] = COLORS[i]
mask[yy, xx] = True
return colors, mask
示例5: circle
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import circle [as 別名]
def circle(self, row: int, col: int, radius: float,
color: ColorType, fill: bool=False, alpha=1.0) -> 'Layer':
"""
Draw a circle centered on the specified row and column,
with the given radius.
:param row: Center row of circle
:param col: Center column of circle
:param radius: Radius of circle
:param color: Color to draw with
:param fill: True if the circle should be filled
:return: This frame instance
"""
if fill:
rr, cc = draw.circle(row, col, round(radius), shape=self.matrix.shape)
self._draw(rr, cc, color, alpha)
else:
rr, cc, aa = draw.circle_perimeter_aa(row, col, round(radius), shape=self.matrix.shape)
self._draw(rr, cc, color, aa)
return self
示例6: visualize
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import circle [as 別名]
def visualize(folder, imagenames, mesh_2d, joints_2d, root=None):
i = 0
for name, mesh, joints in zip(imagenames, mesh_2d, joints_2d):
print(name)
shutil.copyfile(root + name,
'/im_gt_{}.png'.format(folder, i)
)
im = imread(name)
shape = im.shape[0:2]
height = im.shape[0]
for p2d in mesh:
im[height - p2d[1], p2d[0]] = [127,127,127]
for j2d in joints:
rr, cc = circle(height - j2d[1], j2d[0], 2, shape)
im[rr, cc] = [255, 0, 0]
imwrite('{}/im_mask_{}.png'.format(folder, i), im)
i += 1
示例7: create_spot
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import circle [as 別名]
def create_spot(self):
z1, z1a = np.zeros((128, 128)), np.zeros((128, 128))
z2, z2a = np.zeros((128, 128)), np.zeros((128, 128))
rr, cc = draw.circle(30, 90, radius=4, shape=z1.shape) # 30 is y!
z1[rr, cc], z2[rr, cc] = 1, 1
rr2, cc2 = draw.circle(100, 60, radius=4, shape=z2.shape)
z2[rr2, cc2] = 1
rr, cc = draw.circle(30, 90 + 3, radius=4, shape=z1.shape) # 30 is y!
z1a[rr, cc], z2a[rr, cc] = 1, 1
rr2, cc2 = draw.circle(100 - 2, 60, radius=4, shape=z2.shape)
z2a[rr2, cc2] = 1
# marks centers for local com and local_gaussian_method
z1[30, 90], z2[30, 90], z2[100, 60] = 2, 2, 2
z1a[30, 93], z2a[30, 93], z2a[98, 60] = 10, 10, 10
dp = ElectronDiffraction2D(
np.asarray([[z1, z1a], [z2, z2a]])
) # this needs to be in 2x2
return dp
示例8: create_circle_center
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import circle [as 別名]
def create_circle_center(img_shape, centers, radius=10):
""" create initialisation from centres as small circles
:param img_shape:
:param [[int, int]] centers:
:param int radius:
:return:
"""
mask_circle = np.zeros(img_shape, dtype=int)
mask_perimeter = np.zeros(img_shape, dtype=int)
center_circles = list()
for i, pos in enumerate(centers):
rr, cc = draw.circle(int(pos[0]), int(pos[1]), radius,
shape=img_shape[:2])
mask_circle[rr, cc] = i + 1
rr, cc = draw.circle_perimeter(int(pos[0]), int(pos[1]), radius,
shape=img_shape[:2])
mask_perimeter[rr, cc] = i + 1
center_circles.append(np.array([rr, cc]).transpose())
return center_circles, mask_circle, mask_perimeter
示例9: decode_pose
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import circle [as 別名]
def decode_pose(images, net_output, threshold=0.001):
# key point class: 1:visible, 2: invisible, 3: not marked
prediction = decode_output(net_output, threshold=threshold)
batch_size, size_ver, size_hor, keypoints_number = net_output.shape
kp_ver = prediction[:, ::3]
kp_hor = prediction[:, 1::3]
kp_class = prediction[:, 2::3]
for b in range(batch_size):
point_hor = kp_hor[b]
point_ver = kp_ver[b]
point_class = kp_class[b]
images[b, :, :, :] = draw_lines_on_img(images[b], point_ver, point_hor, point_class)
for i in range(len(point_class)):
if point_class[i] != 3:
rr, cc = draw.circle(point_ver[i], point_hor[i], 10, (256, 192))
images[b, rr, cc, :] = 0
return images
示例10: add_clicks
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import circle [as 別名]
def add_clicks(self, inputs, c):
out_imgs = None
for input in inputs:
img = input[:, :, :3]
# Radius of the point to be diplayed
r=3
pts = np.where(input[:,:,3] == 0)
pts_zipped = list(zip(pts[0], pts[1]))
if len(pts[0]) > 0:
for pt in pts_zipped:
if r < pt[0] < img.shape[0] - r and r < pt[1] < img.shape[1] - r:
rr, cc = circle(pt[0], pt[1], 5, img.shape)
img[rr, cc, :] = [np.max(img), np.min(img), np.min(img)] if c == 'r' \
else [np.min(img), np.min(img), np.max(img)]
img = img[np.newaxis, :, :, :]
if out_imgs is None:
out_imgs = img
else:
out_imgs = np.concatenate((out_imgs, img), axis = 0)
return out_imgs.astype(np.float32)
示例11: _snr_approx
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import circle [as 別名]
def _snr_approx(array, source_xy, fwhm, centery, centerx):
"""
array - frame convolved with top hat kernel
"""
sourcex, sourcey = source_xy
rad = dist(centery, centerx, sourcey, sourcex)
ind_aper = draw.circle(sourcey, sourcex, fwhm/2.)
# noise : STDDEV in convolved array of 1px wide annulus (while
# masking the flux aperture) * correction of # of resolution elements
ind_ann = draw.circle_perimeter(int(centery), int(centerx), int(rad))
array2 = array.copy()
array2[ind_aper] = mad(array[ind_ann]) # mask
n2 = (2 * np.pi * rad) / fwhm - 1
noise = array2[ind_ann].std() * np.sqrt(1+(1/n2))
# signal : central px minus the mean of the pxs (masked) in 1px annulus
signal = array[sourcey, sourcex] - array2[ind_ann].mean()
snr_value = signal / noise
return sourcey, sourcex, snr_value
示例12: key_point_to_mask
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import circle [as 別名]
def key_point_to_mask(key_points, img_size, radius=6):
new_points = expand_key_points(key_points, radius)
mask = np.zeros(shape=img_size, dtype=bool)
for i, joint in enumerate(list(key_points) + new_points):
if KEY_POINT_MISSING_VALUE in joint:
continue
yy, xx = circle(joint[0], joint[1], radius=radius, shape=img_size)
mask[yy, xx] = True
mask = dilation(mask, square(radius + 3))
mask = erosion(mask, square(radius + 3))
return mask
示例13: produce_ma_mask
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import circle [as 別名]
def produce_ma_mask(kp_array, img_size, point_radius=4):
from skimage.morphology import dilation, erosion, square
mask = np.zeros(shape=img_size, dtype=bool)
limbs = [[2, 3], [2, 6], [3, 4], [4, 5], [6, 7], [7, 8], [2, 9], [9, 10],
[10, 11], [2, 12], [12, 13], [13, 14], [2, 1], [1, 15], [15, 17],
[1, 16], [16, 18], [2, 17], [2, 18], [9, 12], [12, 6], [9, 3], [17, 18]]
limbs = np.array(limbs) - 1
for f, t in limbs:
from_missing = kp_array[f][0] == MISSING_VALUE or kp_array[f][1] == MISSING_VALUE
to_missing = kp_array[t][0] == MISSING_VALUE or kp_array[t][1] == MISSING_VALUE
if from_missing or to_missing:
continue
norm_vec = kp_array[f] - kp_array[t]
norm_vec = np.array([-norm_vec[1], norm_vec[0]])
norm_vec = point_radius * norm_vec / np.linalg.norm(norm_vec)
vetexes = np.array([
kp_array[f] + norm_vec,
kp_array[f] - norm_vec,
kp_array[t] - norm_vec,
kp_array[t] + norm_vec
])
yy, xx = polygon(vetexes[:, 0], vetexes[:, 1], shape=img_size)
mask[yy, xx] = True
for i, joint in enumerate(kp_array):
if kp_array[i][0] == MISSING_VALUE or kp_array[i][1] == MISSING_VALUE:
continue
yy, xx = circle(joint[0], joint[1], radius=point_radius, shape=img_size)
mask[yy, xx] = True
mask = dilation(mask, square(5))
mask = erosion(mask, square(5))
return mask
示例14: draw_circle
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import circle [as 別名]
def draw_circle(self, center: List, radius: int):
"""
Draw a circle
:param center: center of the circle
:param radius: radius of the circle
:return:
"""
arr = np.zeros(self.canvas_shape, dtype=bool)
xp = [center[0] + radius, center[0], center[0], center[0] - radius]
yp = [center[1], center[1] + radius, center[1] - radius, center[1]]
rr, cc = draw.circle(*center, radius=radius, shape=self.canvas_shape)
arr[cc, rr] = True
return arr
示例15: joints_plot_image
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import circle [as 別名]
def joints_plot_image(joints, weight, img, radius=3, thickness=2):
""" Plot the joints on image
:param joints: (np.array)Assuming input of shape (num, joint_num, dim)
:param img: (image)Assuming input of shape (num, w, h, c)
:param weight: (np.array)Assuming input of shape (num, joint_num)
:param radius: (int)Radius
:param thickness: (int)Thickness
:return: set of RGB image (num, w, h, c)
"""
assert len(joints.shape) == 3 and len(img.shape) == 4 and len(weight.shape) == 2
assert joints.shape[0] == img.shape[0] == weight.shape[0]
colors = [(241, 242, 224), (196, 203, 128), (136, 150, 0), (64, 77, 0),
(201, 230, 200), (132, 199, 129), (71, 160, 67), (32, 94, 27),
(130, 224, 255), (7, 193, 255), (0, 160, 255), (0, 111, 255),
(220, 216, 207), (174, 164, 144), (139, 125, 96), (100, 90, 69),
(252, 229, 179), (247, 195, 79), (229, 155, 3), (155, 87, 1),
(231, 190, 225), (200, 104, 186), (176, 39, 156), (162, 31, 123),
(210, 205, 255), (115, 115, 229), (80, 83, 239), (40, 40, 198)]
ret = np.zeros(img.shape, np.uint8)
assert len(joints.shape) == 3 and len(img.shape) == 4
assert img.shape[-1] == 3
ret = img.copy()
for num in range(joints.shape[0]):
for jnum in range(joints.shape[1]):
if weight[num, jnum] == 1:
rr, cc = draw.circle(
int(joints[num, jnum, 0]), int(joints[num, jnum, 1]), radius)
ret[num, rr, cc] = colors[jnum]
for num in range(joints.shape[0]):
for lnk in range(len(LINKS)):
if weight[num, LINKS[lnk][0]] == 1 and weight[num, LINKS[lnk][1]] == 1:
rr, cc = draw.line(int(joints[num, LINKS[lnk][0], 0]), int(joints[num, LINKS[lnk][0], 1]),
int(joints[num, LINKS[lnk][1], 0]), int(joints[num, LINKS[lnk][1], 1]))
ret[num, rr, cc] = colors[lnk]
return ret