本文整理匯總了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