10 examples of 'imresize python' in Python

Every line of 'imresize python' 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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
34def 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)
51def imresize(im, h, w):
52 raise ImportError(
53 "Neither OpenCV nor the Python Imaging Library (PIL) is "
54 "installed. Please install either for resizing images."
55 )
75def resize(im, res):
76 return np.array([cv2.resize(im[i],res) for i in range(im.shape[0])])
35def resize_keepdims(im, size):
36 # Opencv's resize remove the extra dimension for grayscale images. We add it back.
37 ret = cv2.resize(im, size)
38 if im.ndim == 3 and ret.ndim == 2:
39 ret = ret[:, :, np.newaxis]
40 return ret
9def imresize(im, size, interp='bilinear'):
10 if interp == 'nearest':
11 resample = Image.NEAREST
12 elif interp == 'bilinear':
13 resample = Image.BILINEAR
14 elif interp == 'bicubic':
15 resample = Image.BICUBIC
16 else:
17 raise Exception('resample method undefined!')
18
19 return im.resize(size, resample)
23def resize(im, short, max_size):
24 """Return resized image (NDArray) and scale (float)"""
25 im_shape = im.shape
26 im_size_min = min(im_shape[0:2])
27 im_size_max = max(im_shape[0:2])
28 im_scale = float(short) / float(im_size_min)
29 # prevent bigger axis from being more than max_size:
30 if round(im_scale * im_size_max) > max_size:
31 im_scale = float(max_size) / float(im_size_max)
32 short = int(im_size_min * im_scale)
33 im = mx.image.resize_short(im, short)
34 return im, im_scale
28@curry
29def resize(pil_img, size, interpolation=Image.BILINEAR):
30 return pil_img.resize(size, interpolation)
29def 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
49def _resize(frame):
50 """Resizing function utilizing OpenCV.
51
52 Args:
53 frame: A frame from a cv2.video_reader object to process
54
55 Returns:
56 resized_frame: the frame, resized
57 """
58 resized_frame = cv2.resize(frame,
59 None,
60 fx=RESIZE_FACTOR,
61 fy=RESIZE_FACTOR,
62 interpolation=cv2.INTER_AREA)
63
64 return resized_frame
44def 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

Related snippets