Python cv2.INTER_LANCZOS4 Examples
The following are 30
code examples of cv2.INTER_LANCZOS4().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cv2
, or try the search function
.
Example #1
Source File: resize.py From chainer-compiler with MIT License | 7 votes |
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))
Example #2
Source File: Scaling.py From Finger-Detection-and-Tracking with BSD 2-Clause "Simplified" License | 6 votes |
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()
Example #3
Source File: utils.py From convolutional-pose-machines-tensorflow with Apache License 2.0 | 6 votes |
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
Example #4
Source File: detectfuncs.py From ibeis with Apache License 2.0 | 6 votes |
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)
Example #5
Source File: utils.py From VNect-tensorflow with Apache License 2.0 | 6 votes |
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
Example #6
Source File: utils.py From VNect-tensorflow with Apache License 2.0 | 6 votes |
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
Example #7
Source File: image_processing.py From DeepMosaics with GNU General Public License v3.0 | 6 votes |
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
Example #8
Source File: process_images.py From catalyst with Apache License 2.0 | 6 votes |
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
Example #9
Source File: transforms.py From siamfc-pytorch with MIT License | 6 votes |
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
Example #10
Source File: convert_test.py From SpaceNet_Off_Nadir_Solutions with Apache License 2.0 | 6 votes |
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])
Example #11
Source File: las2fmap.py From DBNet with Apache License 2.0 | 6 votes |
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)
Example #12
Source File: resize.py From chainercv with MIT License | 6 votes |
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))
Example #13
Source File: data_augment.py From PytorchSSD with MIT License | 5 votes |
def preproc_for_test(image, insize, mean, std=(1, 1, 1)): 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 -= mean image /= std return image.transpose(2, 0, 1)
Example #14
Source File: data_augment.py From PytorchSSD with MIT License | 5 votes |
def __call__(self, img): 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), (self.resize, self.resize), interpolation=interp_method).astype(np.float32) img -= self.means img /= self.std img = img.transpose(self.swap) return torch.from_numpy(img)
Example #15
Source File: data_augment.py From RFBNet with MIT License | 5 votes |
def __call__(self, img): 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), (self.resize, self.resize),interpolation = interp_method).astype(np.float32) img -= self.means img = img.transpose(self.swap) return torch.from_numpy(img)
Example #16
Source File: face.py From MMM-Facial-Recognition-OCV3 with MIT License | 5 votes |
def resize(self, image, face_width, face_height): """Resize a face image to the proper size for training and detection. """ return cv2.resize(image, (face_width, face_height), interpolation=cv2.INTER_LANCZOS4)
Example #17
Source File: object_detection_2d_geometric_ops.py From ssd_keras with Apache License 2.0 | 5 votes |
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)
Example #18
Source File: crop_and_upscale.py From Tag2Pix with MIT License | 5 votes |
def upscale_lanczos_all(dataset_path, image_base, save_path): print('upscaling with lanczos...') img_len = len(list(image_base.iterdir())) for img_f in tqdm(image_base.iterdir(), total=img_len): img = cv2.imread(str(img_f), cv2.IMREAD_COLOR) img_up = cv2.resize(img, (768, 768), interpolation=cv2.INTER_LANCZOS4) cv2.imwrite(str(save_path / img_f.name), img_up)
Example #19
Source File: object_detection_2d_geometric_ops.py From keras-FP16-test with Apache License 2.0 | 5 votes |
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)
Example #20
Source File: data_augment.py From FaceBoxes.PyTorch with MIT License | 5 votes |
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)
Example #21
Source File: data_augment.py From InsightFace-v2 with Apache License 2.0 | 5 votes |
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)
Example #22
Source File: data_augment.py From LFIP with MIT License | 5 votes |
def __call__(self, img): 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), (self.resize, self.resize),interpolation = interp_method).astype(np.float32) img -= self.means img = img.transpose(self.swap) return torch.from_numpy(img)
Example #23
Source File: data_augment.py From LFIP with MIT License | 5 votes |
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, insize), interpolation=interp_method) image = image.astype(np.float32) image -= mean return image.transpose(2, 0, 1)
Example #24
Source File: image_processing.py From DeepMosaics with GNU General Public License v3.0 | 5 votes |
def replace_mosaic(img_origin,img_fake,mask,x,y,size,no_father): img_fake = cv2.resize(img_fake,(size*2,size*2),interpolation=cv2.INTER_LANCZOS4) if no_father: img_origin[y-size:y+size,x-size:x+size]=img_fake img_result = img_origin else: #color correction RGB_origin = img_origin[y-size:y+size,x-size:x+size].mean(0).mean(0) RGB_fake = img_fake.mean(0).mean(0) for i in range(3):img_fake[:,:,i] = np.clip(img_fake[:,:,i]+RGB_origin[i]-RGB_fake[i],0,255) #eclosion eclosion_num = int(size/5) entad = int(eclosion_num/2+2) # mask = np.zeros(img_origin.shape, dtype='uint8') # mask = cv2.rectangle(mask,(x-size+entad,y-size+entad),(x+size-entad,y+size-entad),(255,255,255),-1) mask = cv2.resize(mask,(img_origin.shape[1],img_origin.shape[0])) mask = ch_one2three(mask) mask = (cv2.blur(mask, (eclosion_num, eclosion_num))) mask_tmp = np.zeros_like(mask) mask_tmp[y-size:y+size,x-size:x+size] = mask[y-size:y+size,x-size:x+size]# Fix edge overflow mask = mask_tmp/255.0 img_tmp = np.zeros(img_origin.shape) img_tmp[y-size:y+size,x-size:x+size]=img_fake img_result = img_origin.copy() img_result = (img_origin*(1-mask)+img_tmp*mask).astype('uint8') return img_result
Example #25
Source File: data.py From DeepMosaics with GNU General Public License v3.0 | 5 votes |
def random_transform_video(src,target,finesize,N): #random crop h,w = target.shape[:2] h_move = int((h-finesize)*random.random()) w_move = int((w-finesize)*random.random()) # print(h,w,h_move,w_move) target = target[h_move:h_move+finesize,w_move:w_move+finesize,:] src = src[h_move:h_move+finesize,w_move:w_move+finesize,:] #random flip if random.random()<0.5: src = src[:,::-1,:] target = target[:,::-1,:] #random color alpha = random.uniform(-0.1,0.1) beta = random.uniform(-0.1,0.1) b = random.uniform(-0.05,0.05) g = random.uniform(-0.05,0.05) r = random.uniform(-0.05,0.05) for i in range(N): src[:,:,i*3:(i+1)*3] = color_adjust(src[:,:,i*3:(i+1)*3],alpha,beta,b,g,r) target = color_adjust(target,alpha,beta,b,g,r) #random blur if random.random()<0.5: interpolations = [cv2.INTER_LINEAR,cv2.INTER_CUBIC,cv2.INTER_LANCZOS4] size_ran = random.uniform(0.7,1.5) interpolation_up = interpolations[random.randint(0,2)] interpolation_down =interpolations[random.randint(0,2)] tmp = cv2.resize(src[:,:,:3*N], (int(finesize*size_ran),int(finesize*size_ran)),interpolation=interpolation_up) src[:,:,:3*N] = cv2.resize(tmp, (finesize,finesize),interpolation=interpolation_down) tmp = cv2.resize(target, (int(finesize*size_ran),int(finesize*size_ran)),interpolation=interpolation_up) target = cv2.resize(tmp, (finesize,finesize),interpolation=interpolation_down) return src,target
Example #26
Source File: runmodel.py From DeepMosaics with GNU General Public License v3.0 | 5 votes |
def traditional_cleaner(img,opt): h,w = img.shape[:2] img = cv2.blur(img, (opt.tr_blur,opt.tr_blur)) img = img[::opt.tr_down,::opt.tr_down,:] img = cv2.resize(img, (w,h),interpolation=cv2.INTER_LANCZOS4) return img
Example #27
Source File: data_augment.py From LRF-Net with MIT License | 5 votes |
def __call__(self, img): 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), (self.resize, self.resize),interpolation = interp_method).astype(np.float32) img -= self.means img = img.transpose(self.swap) return torch.from_numpy(img)
Example #28
Source File: data_augment.py From LRF-Net with MIT License | 5 votes |
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, insize), interpolation=interp_method) image = image.astype(np.float32) image -= mean return image.transpose(2, 0, 1)
Example #29
Source File: data_augment.py From Face-Detector-1MB-with-landmark with MIT License | 5 votes |
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)
Example #30
Source File: data_augment.py From S3FD.PyTorch with Apache License 2.0 | 5 votes |
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, insize), interpolation=interp_method) image = image.astype(np.float32) image -= mean return image.transpose(2, 0, 1)