本文整理汇总了Python中cv2.INTER_LANCZOS4属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.INTER_LANCZOS4属性的具体用法?Python cv2.INTER_LANCZOS4怎么用?Python cv2.INTER_LANCZOS4使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类cv2
的用法示例。
在下文中一共展示了cv2.INTER_LANCZOS4属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _resize_cv2
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_LANCZOS4 [as 别名]
def _resize_cv2(img, size, interpolation):
img = img.transpose((1, 2, 0))
if interpolation == PIL.Image.NEAREST:
cv_interpolation = cv2.INTER_NEAREST
elif interpolation == PIL.Image.BILINEAR:
cv_interpolation = cv2.INTER_LINEAR
elif interpolation == PIL.Image.BICUBIC:
cv_interpolation = cv2.INTER_CUBIC
elif interpolation == PIL.Image.LANCZOS:
cv_interpolation = cv2.INTER_LANCZOS4
H, W = size
img = cv2.resize(img, dsize=(W, H), interpolation=cv_interpolation)
# If input is a grayscale image, cv2 returns a two-dimentional array.
if len(img.shape) == 2:
img = img[:, :, np.newaxis]
return img.transpose((2, 0, 1))
示例2: _resize
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_LANCZOS4 [as 别名]
def _resize(image, t_width=None, t_height=None, verbose=False):
if verbose:
print('RESIZING WITH t_width = %r and t_height = %r' % (t_width, t_height, ))
height, width = image.shape[:2]
if t_width is None and t_height is None:
return image
elif t_width is not None and t_height is not None:
pass
elif t_width is None:
t_width = (width / height) * float(t_height)
elif t_height is None:
t_height = (height / width) * float(t_width)
t_width, t_height = float(t_width), float(t_height)
t_width, t_height = int(np.around(t_width)), int(np.around(t_height))
assert t_width > 0 and t_height > 0, 'target size too small'
assert t_width <= width * 10 and t_height <= height * 10, 'target size too large (capped at 1000%)'
# interpolation = cv2.INTER_LANCZOS4
interpolation = cv2.INTER_LINEAR
return cv2.resize(image, (t_width, t_height), interpolation=interpolation)
示例3: read_square_image
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_LANCZOS4 [as 别名]
def read_square_image(file, cam, boxsize, type):
# from file
if type == 'IMAGE':
oriImg = cv2.imread(file)
# from webcam
elif type == 'WEBCAM':
_, oriImg = cam.read()
scale = boxsize / (oriImg.shape[0] * 1.0)
imageToTest = cv2.resize(oriImg, (0, 0), fx=scale, fy=scale, interpolation=cv2.INTER_LANCZOS4)
output_img = np.ones((boxsize, boxsize, 3)) * 128
if imageToTest.shape[1] < boxsize:
offset = imageToTest.shape[1] % 2
output_img[:, int(boxsize/2-math.ceil(imageToTest.shape[1]/2)):int(boxsize/2+math.ceil(imageToTest.shape[1]/2)+offset), :] = imageToTest
else:
output_img = imageToTest[:, int(imageToTest.shape[1]/2-boxsize/2):int(imageToTest.shape[1]/2+boxsize/2), :]
return output_img
示例4: _crop
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_LANCZOS4 [as 别名]
def _crop(self, img, box, out_size):
# convert box to 0-indexed and center based [y, x, h, w]
box = np.array([
box[1] - 1 + (box[3] - 1) / 2,
box[0] - 1 + (box[2] - 1) / 2,
box[3], box[2]], dtype=np.float32)
center, target_sz = box[:2], box[2:]
context = self.context * np.sum(target_sz)
size = np.sqrt(np.prod(target_sz + context))
size *= out_size / self.exemplar_sz
avg_color = np.mean(img, axis=(0, 1), dtype=float)
interp = np.random.choice([
cv2.INTER_LINEAR,
cv2.INTER_CUBIC,
cv2.INTER_AREA,
cv2.INTER_NEAREST,
cv2.INTER_LANCZOS4])
patch = ops.crop_and_resize(
img, center, size, out_size,
border_value=avg_color, interp=interp)
return patch
示例5: main
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_LANCZOS4 [as 别名]
def main():
imageOne = cv2.imread("../data/4.1.04.tiff", 1)
areaInter = cv2.resize(imageOne, None, fx=3, fy=3, interpolation=cv2.INTER_AREA)
cubicInter = cv2.resize(imageOne, None, fx=3, fy=3, interpolation=cv2.INTER_CUBIC)
linearInter = cv2.resize(imageOne, None, fx=3, fy=3, interpolation=cv2.INTER_LINEAR)
nearestInter = cv2.resize(imageOne, None, fx=3, fy=3, interpolation=cv2.INTER_NEAREST)
lancz0s4Inter = cv2.resize(imageOne, None, fx=3, fy=3, interpolation=cv2.INTER_LANCZOS4)
cv2.imshow("Area Interpolation Image", areaInter)
cv2.imshow("Cubic Interpolation Image", cubicInter)
cv2.imshow("Linear Interpolation Image", linearInter)
cv2.imshow("Nearest Interpolation Image", nearestInter)
cv2.imshow("LANCZ0S4 Interpolation Image", lancz0s4Inter)
cv2.waitKey(0)
cv2.destroyAllWindows()
示例6: process_image
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_LANCZOS4 [as 别名]
def process_image(img_id):
if 'Pan-Sharpen_' in img_id:
img_id = img_id.split('Pan-Sharpen_')[1]
img = io.imread(path.join(test_dir, '_'.join(img_id.split('_')[:4]), 'Pan-Sharpen', 'Pan-Sharpen_' + img_id+'.tif'))
nir = img[:, :, 3:]
img = img[:, :, :3]
np.clip(img, None, threshold, out=img)
img = np.floor_divide(img, threshold / 255).astype('uint8')
cv2.imwrite(path.join(test_png, img_id + '.png'), img, [cv2.IMWRITE_PNG_COMPRESSION, 9])
img2 = io.imread(path.join(test_dir, '_'.join(img_id.split('_')[:4]), 'MS', 'MS_' + img_id+'.tif'))
img2 = np.rollaxis(img2, 0, 3)
img2 = cv2.resize(img2, (900, 900), interpolation=cv2.INTER_LANCZOS4)
img_0_3_5 = (np.clip(img2[..., [0, 3, 5]], None, (2000, 3000, 3000)) / (np.array([2000, 3000, 3000]) / 255)).astype('uint8')
cv2.imwrite(path.join(test_png2, img_id + '.png'), img_0_3_5, [cv2.IMWRITE_PNG_COMPRESSION, 9])
pan = io.imread(path.join(test_dir, '_'.join(img_id.split('_')[:4]), 'PAN', 'PAN_' + img_id+'.tif'))
pan = pan[..., np.newaxis]
img_pan_6_7 = np.concatenate([pan, img2[..., 7:], nir], axis=2)
img_pan_6_7 = (np.clip(img_pan_6_7, None, (3000, 5000, 5000)) / (np.array([3000, 5000, 5000]) / 255)).astype('uint8')
cv2.imwrite(path.join(test_png3, img_id + '.png'), img_pan_6_7, [cv2.IMWRITE_PNG_COMPRESSION, 9])
示例7: resize
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_LANCZOS4 [as 别名]
def resize(img,size,interpolation=cv2.INTER_LINEAR):
'''
cv2.INTER_NEAREST 最邻近插值点法
cv2.INTER_LINEAR 双线性插值法
cv2.INTER_AREA 邻域像素再取样插补
cv2.INTER_CUBIC 双立方插补,4*4大小的补点
cv2.INTER_LANCZOS4 8x8像素邻域的Lanczos插值
'''
h, w = img.shape[:2]
if np.min((w,h)) ==size:
return img
if w >= h:
res = cv2.resize(img,(int(size*w/h), size),interpolation=interpolation)
else:
res = cv2.resize(img,(size, int(size*h/w)),interpolation=interpolation)
return res
示例8: __init__
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_LANCZOS4 [as 别名]
def __init__(
self,
in_dir: Path,
out_dir: Path,
max_size: int = None,
clear_exif: bool = True,
grayscale: bool = False,
expand_dims: bool = True,
interpolation=cv2.INTER_LANCZOS4,
):
"""@TODO: Docs. Contribution is welcome."""
self.in_dir = in_dir
self.out_dir = out_dir
self.grayscale = grayscale
self.expand_dims = expand_dims
self.max_size = max_size
self.clear_exif = clear_exif
self.interpolation = interpolation
示例9: rotate_about_center
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_LANCZOS4 [as 别名]
def rotate_about_center(src, angle, scale=1.):
"""
Rotate images based on there centers
:param src: one image (opencv format)
:param angle: rotated angle
:param scale: re-scaling images [default: 1.]
"""
w = src.shape[1]
h = src.shape[0]
rangle = np.deg2rad(angle) # angle in radians
# now calculate new image width and height
nw = (abs(np.sin(rangle)*h) + abs(np.cos(rangle)*w))*scale
nh = (abs(np.cos(rangle)*h) + abs(np.sin(rangle)*w))*scale
# ask opencv for the rotation matrix
rot_mat = cv2.getRotationMatrix2D((nw*0.5, nh*0.5), angle, scale)
# calculate the move from the old center to the new center combined
# with the rotation
rot_move = np.dot(rot_mat, np.array([(nw-w)*0.5, (nh-h)*0.5,0]))
# the move only affects the translation, so update the translation
# part of the transform
rot_mat[0,2] += rot_move[0]
rot_mat[1,2] += rot_move[1]
return cv2.warpAffine(src, rot_mat, (int(math.ceil(nw)), int(math.ceil(nh))), flags=cv2.INTER_LANCZOS4)
示例10: _resize_subtract_mean
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_LANCZOS4 [as 别名]
def _resize_subtract_mean(image, insize, rgb_mean):
interp_methods = [cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_NEAREST, cv2.INTER_LANCZOS4]
interp_method = interp_methods[random.randrange(5)]
image = cv2.resize(image, (insize, insize), interpolation=interp_method)
image = image.astype(np.float32)
image -= rgb_mean
return image.transpose(2, 0, 1)
示例11: resize_dataset_image
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_LANCZOS4 [as 别名]
def resize_dataset_image(img, out_w=256, out_h=256):
img2 = copy_to_cpu(img)
img2 = img2.transpose((1, 2, 0))
img2 = cv2.resize(img2, (out_h, out_w), cv2.INTER_LANCZOS4)
img2 = img2.transpose((2, 0, 1))
try:
if type(img) == cupy.core.core.ndarray:
img2 = cuda.to_gpu(img2)
except:
pass
return img2
# b, ch, w, h
示例12: preproc_for_test
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_LANCZOS4 [as 别名]
def preproc_for_test(image, insize, mean):
interp_methods = [cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_NEAREST, cv2.INTER_LANCZOS4]
interp_method = interp_methods[random.randrange(5)]
image = cv2.resize(image, (insize[0], insize[1]),interpolation=interp_method)
image = image.astype(np.float32)
image -= mean
return image.transpose(2, 0, 1)
示例13: __init__
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_LANCZOS4 [as 别名]
def __init__(self,
height,
width,
interpolation_modes=[cv2.INTER_NEAREST,
cv2.INTER_LINEAR,
cv2.INTER_CUBIC,
cv2.INTER_AREA,
cv2.INTER_LANCZOS4],
box_filter=None,
labels_format={'class_id': 0, 'xmin': 1, 'ymin': 2, 'xmax': 3, 'ymax': 4}):
'''
Arguments:
height (int): The desired height of the output image in pixels.
width (int): The desired width of the output image in pixels.
interpolation_modes (list/tuple, optional): A list/tuple of integers
that represent valid OpenCV interpolation modes. For example,
integers 0 through 5 are valid interpolation modes.
box_filter (BoxFilter, optional): Only relevant if ground truth bounding boxes are given.
A `BoxFilter` object to filter out bounding boxes that don't meet the given criteria
after the transformation. Refer to the `BoxFilter` documentation for details. If `None`,
the validity of the bounding boxes is not checked.
labels_format (dict, optional): A dictionary that defines which index in the last axis of the labels
of an image contains which bounding box coordinate. The dictionary maps at least the keywords
'xmin', 'ymin', 'xmax', and 'ymax' to their respective indices within last axis of the labels array.
'''
if not (isinstance(interpolation_modes, (list, tuple))):
raise ValueError("`interpolation_mode` must be a list or tuple.")
self.height = height
self.width = width
self.interpolation_modes = interpolation_modes
self.box_filter = box_filter
self.labels_format = labels_format
self.resize = Resize(height=self.height,
width=self.width,
box_filter=self.box_filter,
labels_format=self.labels_format)
开发者ID:pierluigiferrari,项目名称:data_generator_object_detection_2d,代码行数:38,代码来源:object_detection_2d_geometric_ops.py
示例14: preproc_for_test
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_LANCZOS4 [as 别名]
def preproc_for_test(image, input_size, mean, std):
interp_methods = [cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_NEAREST, cv2.INTER_LANCZOS4]
interp_method = interp_methods[random.randrange(5)]
image = cv2.resize(image, input_size,interpolation=interp_method)
image = image.astype(np.float32)
image = image[:,:,::-1]
image /= 255.
if mean is not None:
image -= mean
if std is not None:
image /= std
return image.transpose(2, 0, 1)
示例15: __call__
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_LANCZOS4 [as 别名]
def __call__(self, img, res, input_size):
interp_methods = [cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_NEAREST, cv2.INTER_LANCZOS4]
interp_method = interp_methods[0]
img = cv2.resize(np.array(img), input_size,
interpolation = interp_method).astype(np.float32)
img = img[:,:,::-1]
img /= 255.
if self.means is not None:
img -= self.means
if self.std is not None:
img /= self.std
img = img.transpose(self.swap)
img = np.ascontiguousarray(img, dtype=np.float32)
return torch.from_numpy(img), torch.zeros(1,5)