MCPcopy Create free account
hub / github.com/Robbyant/lingbot-depth / preprocess_input_image

Function preprocess_input_image

example.py:24–54  ·  view source on GitHub ↗

Load and preprocess RGB image. Args: image_path (str): Path to RGB image device (torch.device): Device to load tensor on Returns: tuple: (numpy_image, tensor_image) - numpy_image: RGB numpy array (H, W, 3), uint8 - tensor_image: RGB tens

(image_path, device)

Source from the content-addressed store, hash-verified

22
23
24def preprocess_input_image(image_path, device):
25 """
26 Load and preprocess RGB image.
27
28 Args:
29 image_path (str): Path to RGB image
30 device (torch.device): Device to load tensor on
31
32 Returns:
33 tuple: (numpy_image, tensor_image)
34 - numpy_image: RGB numpy array (H, W, 3), uint8
35 - tensor_image: RGB tensor (1, 3, H, W), float32, [0,1]
36 """
37 if not Path(image_path).exists():
38 raise FileNotFoundError(f"Image not found: {image_path}")
39
40 # Read image and convert BGR to RGB
41 image_np = cv2.imread(image_path)
42 if image_np is None:
43 raise ValueError(f"Failed to read image: {image_path}")
44
45 image_np = cv2.cvtColor(image_np, cv2.COLOR_BGR2RGB)
46
47 # Convert to tensor and normalize to [0, 1]
48 image_tensor = torch.tensor(
49 image_np / 255.0,
50 dtype=torch.float32,
51 device=device
52 ).permute(2, 0, 1).unsqueeze(0)
53
54 return image_np, image_tensor
55
56
57def load_depth_map(depth_path, scale=1000.0):

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected