MCPcopy Create free account
hub / github.com/VisionXLab/OF-Diff / apply_min_size

Function apply_min_size

ldm/modules/midas/midas/transforms.py:6–45  ·  view source on GitHub ↗

Rezise the sample to ensure the given size. Keeps aspect ratio. Args: sample (dict): sample size (tuple): image size Returns: tuple: new size

(sample, size, image_interpolation_method=cv2.INTER_AREA)

Source from the content-addressed store, hash-verified

4
5
6def apply_min_size(sample, size, image_interpolation_method=cv2.INTER_AREA):
7 """Rezise the sample to ensure the given size. Keeps aspect ratio.
8
9 Args:
10 sample (dict): sample
11 size (tuple): image size
12
13 Returns:
14 tuple: new size
15 """
16 shape = list(sample["disparity"].shape)
17
18 if shape[0] >= size[0] and shape[1] >= size[1]:
19 return sample
20
21 scale = [0, 0]
22 scale[0] = size[0] / shape[0]
23 scale[1] = size[1] / shape[1]
24
25 scale = max(scale)
26
27 shape[0] = math.ceil(scale * shape[0])
28 shape[1] = math.ceil(scale * shape[1])
29
30 # resize
31 sample["image"] = cv2.resize(
32 sample["image"], tuple(shape[::-1]), interpolation=image_interpolation_method
33 )
34
35 sample["disparity"] = cv2.resize(
36 sample["disparity"], tuple(shape[::-1]), interpolation=cv2.INTER_NEAREST
37 )
38 sample["mask"] = cv2.resize(
39 sample["mask"].astype(np.float32),
40 tuple(shape[::-1]),
41 interpolation=cv2.INTER_NEAREST,
42 )
43 sample["mask"] = sample["mask"].astype(bool)
44
45 return tuple(shape)
46
47
48class Resize(object):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected