MCPcopy Index your code
hub / github.com/thygate/stable-diffusion-webui-depthmap-script / Resize

Class Resize

dmidas/transforms.py:48–194  ·  view source on GitHub ↗

Resize sample to given size (width, height).

Source from the content-addressed store, hash-verified

46
47
48class Resize(object):
49 """Resize sample to given size (width, height).
50 """
51
52 def __init__(
53 self,
54 width,
55 height,
56 resize_target=True,
57 keep_aspect_ratio=False,
58 ensure_multiple_of=1,
59 resize_method="lower_bound",
60 image_interpolation_method=cv2.INTER_AREA,
61 ):
62 """Init.
63
64 Args:
65 width (int): desired output width
66 height (int): desired output height
67 resize_target (bool, optional):
68 True: Resize the full sample (image, mask, target).
69 False: Resize image only.
70 Defaults to True.
71 keep_aspect_ratio (bool, optional):
72 True: Keep the aspect ratio of the input sample.
73 Output sample might not have the given width and height, and
74 resize behaviour depends on the parameter 'resize_method'.
75 Defaults to False.
76 ensure_multiple_of (int, optional):
77 Output width and height is constrained to be multiple of this parameter.
78 Defaults to 1.
79 resize_method (str, optional):
80 "lower_bound": Output will be at least as large as the given size.
81 "upper_bound": Output will be at max as large as the given size. (Output size might be smaller than given size.)
82 "minimal": Scale as least as possible. (Output size might be smaller than given size.)
83 Defaults to "lower_bound".
84 """
85 self.__width = width
86 self.__height = height
87
88 self.__resize_target = resize_target
89 self.__keep_aspect_ratio = keep_aspect_ratio
90 self.__multiple_of = ensure_multiple_of
91 self.__resize_method = resize_method
92 self.__image_interpolation_method = image_interpolation_method
93
94 def constrain_to_multiple_of(self, x, min_val=0, max_val=None):
95 y = (np.round(x / self.__multiple_of) * self.__multiple_of).astype(int)
96
97 if max_val is not None and y > max_val:
98 y = (np.floor(x / self.__multiple_of) * self.__multiple_of).astype(int)
99
100 if y < min_val:
101 y = (np.ceil(x / self.__multiple_of) * self.__multiple_of).astype(int)
102
103 return y
104
105 def get_size(self, width, height):

Callers 4

load_modelFunction · 0.90
estimatemidasFunction · 0.90
estimatedepthanythingFunction · 0.90
estimatemidasBoostFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected