本文整理汇总了Python中cv2.pow方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.pow方法的具体用法?Python cv2.pow怎么用?Python cv2.pow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv2
的用法示例。
在下文中一共展示了cv2.pow方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_random_manipulation
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import pow [as 别名]
def get_random_manipulation(img, manipulation=None):
if manipulation == None:
manipulation = random.choice(MANIPULATIONS)
if manipulation.startswith('jpg'):
quality = int(manipulation[3:])
out = BytesIO()
im = Image.fromarray(img)
im.save(out, format='jpeg', quality=quality)
im_decoded = jpeg.JPEG(np.frombuffer(out.getvalue(), dtype=np.uint8)).decode()
del out
del im
elif manipulation.startswith('gamma'):
gamma = float(manipulation[5:])
# alternatively use skimage.exposure.adjust_gamma
# img = skimage.exposure.adjust_gamma(img, gamma)
im_decoded = np.uint8(cv2.pow(img / 255., gamma)*255.)
elif manipulation.startswith('bicubic'):
scale = float(manipulation[7:])
im_decoded = cv2.resize(img,(0,0), fx=scale, fy=scale, interpolation = cv2.INTER_CUBIC)
else:
assert False
return im_decoded, MANIPULATIONS.index(manipulation)
示例2: farthest_point
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import pow [as 别名]
def farthest_point(defects, contour, centroid):
if defects is not None and centroid is not None:
s = defects[:, 0][:, 0]
cx, cy = centroid
x = np.array(contour[s][:, 0][:, 0], dtype=np.float)
y = np.array(contour[s][:, 0][:, 1], dtype=np.float)
xp = cv2.pow(cv2.subtract(x, cx), 2)
yp = cv2.pow(cv2.subtract(y, cy), 2)
dist = cv2.sqrt(cv2.add(xp, yp))
dist_max_i = np.argmax(dist)
if dist_max_i < len(s):
farthest_defect = s[dist_max_i]
farthest_point = tuple(contour[farthest_defect][0])
return farthest_point
else:
return None
示例3: convert_to_nearest_label
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import pow [as 别名]
def convert_to_nearest_label(label_path, image_size, apply_ignore=True):
"""
Convert RGB label image to onehot label image
:param label_path: File path of RGB label image
:param image_size: Size to resize result image
:param apply_ignore: Apply ignore
:return:
"""
label = np.array(Image.open(label_path).resize((image_size[0], image_size[1]), Image.ANTIALIAS))[:, :, :3]
label = label.astype(np.float32)
stacked_label = list()
for index, mask in enumerate(label_mask):
length = np.sum(cv2.pow(label - mask, 2), axis=2, keepdims=False)
length = cv2.sqrt(length)
stacked_label.append(length)
stacked_label = np.array(stacked_label)
stacked_label = np.transpose(stacked_label, [1, 2, 0])
converted_to_classes = np.argmin(stacked_label, axis=2).astype(np.uint8)
if apply_ignore:
ignore_mask = (converted_to_classes == (len(label_mask) - 1)).astype(np.uint8)
ignore_mask *= (256 - len(label_mask))
converted_to_classes += ignore_mask
return converted_to_classes
示例4: imcv2_recolor
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import pow [as 别名]
def imcv2_recolor(im, a = .1):
t = [np.random.uniform()]
t += [np.random.uniform()]
t += [np.random.uniform()]
t = np.array(t) * 2. - 1.
# random amplify each channel
im = im * (1 + t * a)
mx = 255. * (1 + a)
up = np.random.uniform() * 2 - 1
# im = np.power(im/mx, 1. + up * .5)
im = cv2.pow(im/mx, 1. + up * .5)
return np.array(im * 255., np.uint8)
示例5: imcv2_recolor
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import pow [as 别名]
def imcv2_recolor(im, a=.1):
t = [np.random.uniform()]
t += [np.random.uniform()]
t += [np.random.uniform()]
t = np.array(t) * 2. - 1.
# random amplify each channel
im = im * (1 + t * a)
mx = 255. * (1 + a)
up = np.random.uniform() * 2 - 1
# im = np.power(im/mx, 1. + up * .5)
im = cv2.pow(im / mx, 1. + up * .5)
return np.array(im * 255., np.uint8)
开发者ID:MahmudulAlam,项目名称:Automatic-Identification-and-Counting-of-Blood-Cells,代码行数:15,代码来源:im_transform.py
示例6: _gamma_manip
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import pow [as 别名]
def _gamma_manip(image, gamma):
result = np.uint8(cv2.pow(image / 255., gamma) * 255.)
return result