Every line of 'matplotlib resize image' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
34 def imresize(im, h, w): 35 if im.shape[:2] == (h, w): 36 return im 37 38 # This has problems re-reading a numpy array if it's not 8-bit anymore. 39 assert im.max() > 1, "PIL has problems resizing images after they've been changed to e.g. [0-1] range. Either install OpenCV or resize right after reading the image." 40 img = _Image.fromarray(im.astype(_np.uint8)) 41 return _np.array(img.resize((w,h), _Image.BILINEAR), dtype=im.dtype)
34 def resize_image(image, size, mode=None): 35 return misc.imresize(image, size=size, mode=mode)
38 def image_resize(image, width = None, height = None, inter = cv2.INTER_AREA): 39 # ref: https://stackoverflow.com/questions/44650888/resize-an-image-without-distortion-opencv 40 41 # initialize the dimensions of the image to be resized and 42 # grab the image size 43 dim = None 44 (h, w) = image.shape[:2] 45 46 # if both the width and height are None, then return the 47 # original image 48 if width is None and height is None: 49 return image 50 51 # check to see if the width is None 52 if width is None: 53 # calculate the ratio of the height and construct the 54 # dimensions 55 r = height / float(h) 56 dim = (int(w * r), height) 57 58 # otherwise, the height is None 59 else: 60 # calculate the ratio of the width and construct the 61 # dimensions 62 r = width / float(w) 63 dim = (width, int(h * r)) 64 65 # resize the image 66 resized = cv2.resize(image, dim, interpolation = inter) 67 68 # return the resized image 69 return resized
28 @curry 29 def resize(pil_img, size, interpolation=Image.BILINEAR): 30 return pil_img.resize(size, interpolation)
141 def resize(self, width, height, resample_algorithm=nearest, resize_canvas=True): 142 pixels = resample_algorithm.resize( 143 self, width, height, resize_canvas=resize_canvas 144 ) 145 return self._copy(pixels)
29 def imresize(img, size, return_scale=False, interpolation='bilinear'): 30 """Resize image to a given size. 31 32 Args: 33 img (ndarray): The input image. 34 size (tuple): Target (w, h). 35 return_scale (bool): Whether to return `w_scale` and `h_scale`. 36 interpolation (str): Interpolation method, accepted values are 37 "nearest", "bilinear", "bicubic", "area", "lanczos". 38 39 Returns: 40 tuple or ndarray: (`resized_img`, `w_scale`, `h_scale`) or 41 `resized_img`. 42 """ 43 h, w = img.shape[:2] 44 resized_img = cv2.resize( 45 img, size, interpolation=interp_codes[interpolation]) 46 if not return_scale: 47 return resized_img 48 else: 49 w_scale = size[0] / w 50 h_scale = size[1] / h 51 return resized_img, w_scale, h_scale
26 def resize_image(image,w,h): 27 image=cv2.resize(image,(w,h)) 28 cv2.imwrite(Folder_name+"/Resize-"+str(w)+"*"+str(h)+Extension, image)
33 def _resize_pil(img, size, interpolation): 34 C = img.shape[0] 35 H, W = size 36 out = np.empty((C, H, W), dtype=img.dtype) 37 for ch, out_ch in zip(img, out): 38 ch = PIL.Image.fromarray(ch, mode='F') 39 out_ch[:] = ch.resize((W, H), resample=interpolation) 40 return out
44 def resize_img(img, size, interpolation=PIL.Image.BILINEAR): 45 """Resize image to match the given shape. 46 47 This method uses :mod:`cv2` or :mod:`PIL` for the backend. 48 If :mod:`cv2` is installed, this legacy uses the implementation in 49 :mod:`cv2`. This implementation is faster than the implementation in 50 :mod:`PIL`. Under Anaconda environment, 51 :mod:`cv2` can be installed by the following command. 52 53 .. code:: 54 55 $ conda install -c menpo opencv3=3.2.0 56 57 Args: 58 img (~numpy.ndarray): An array to be transformed. 59 This is in CHW format and the type should be :obj:`numpy.float32`. 60 size (tuple): This is a tuple of length 2. Its elements are 61 ordered as (height, width). 62 interpolation (int): Determines sampling strategy. This is one of 63 :obj:`PIL.Image.NEAREST`, :obj:`PIL.Image.BILINEAR`, 64 :obj:`PIL.Image.BICUBIC`, :obj:`PIL.Image.LANCZOS`. 65 Bilinear interpolation is the default strategy. 66 67 Returns: 68 ~numpy.ndarray: A resize array in CHW format. 69 70 """ 71 img = _resize(img, size, interpolation) 72 return img
676 def apply_resize(image, resize_param): 677 assert isinstance(resize_param.interp_mode, (list, tuple)) 678 679 interp_mode = cv2.INTER_LINEAR 680 num_interp_mode = len(resize_param.interp_mode) 681 if num_interp_mode > 0: 682 probs = [1. / num_interp_mode] * num_interp_mode 683 cumulative = np.cumsum(probs) 684 val = random.uniform(0, cumulative[-1]) 685 prob_num = bisect.bisect_left(cumulative, val) 686 interp_mode = resize_param.interp_mode[prob_num] 687 688 if resize_param.resize_mode == ResizeParameter.WARP: 689 return cv2.resize(image, dsize=(resize_param.width, resize_param.height), interpolation=interp_mode) 690 elif resize_param.resize_mode == ResizeParameter.FIT_LARGE_SIZE_AND_PAD: 691 return aspect_keeping_resize_and_pad(image, resize_param.width, resize_param.height, resize_param.pad_mode, 692 resize_param.pad_val, interp_mode) 693 elif resize_param.resize_mode == ResizeParameter.FIT_SMALL_SIZE: 694 return aspect_keeping_resize_by_small(image, resize_param.width, resize_param.height, interp_mode) 695 raise Exception()