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

Function resize_image

ldm/modules/midas/utils.py:116–148  ·  view source on GitHub ↗

Resize image and make it fit for network. Args: img (array): image Returns: tensor: data ready for network

(img)

Source from the content-addressed store, hash-verified

114
115
116def resize_image(img):
117 """Resize image and make it fit for network.
118
119 Args:
120 img (array): image
121
122 Returns:
123 tensor: data ready for network
124 """
125 height_orig = img.shape[0]
126 width_orig = img.shape[1]
127
128 if width_orig > height_orig:
129 scale = width_orig / 384
130 else:
131 scale = height_orig / 384
132
133 # if width_orig > height_orig:
134 # scale = width_orig / 512
135 # else:
136 # scale = height_orig / 512
137
138 height = (np.ceil(height_orig / scale / 32) * 32).astype(int)
139 width = (np.ceil(width_orig / scale / 32) * 32).astype(int)
140
141 img_resized = cv2.resize(img, (width, height), interpolation=cv2.INTER_AREA)
142
143 img_resized = (
144 torch.from_numpy(np.transpose(img_resized, (2, 0, 1))).contiguous().float()
145 )
146 img_resized = img_resized.unsqueeze(0)
147
148 return img_resized
149
150
151def resize_depth(depth, width, height):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected