MCPcopy Create free account
hub / github.com/aigc3d/LHM / preprocess

Method preprocess

LHM/utils/preprocess.py:32–46  ·  view source on GitHub ↗
(self, image_path: str, save_path: str, rmbg: bool = True, recenter: bool = True, size: int = 512, border_ratio: float = 0.2)

Source from the content-addressed store, hash-verified

30 )
31
32 def preprocess(self, image_path: str, save_path: str, rmbg: bool = True, recenter: bool = True, size: int = 512, border_ratio: float = 0.2):
33 image = self.step_load_to_size(image_path=image_path, size=size*2)
34 if rmbg:
35 image = self.step_rembg(image_in=image)
36 else:
37 image = cv2.cvtColor(image, cv2.COLOR_BGR2BGRA)
38 if recenter:
39 image = self.step_recenter(image_in=image, border_ratio=border_ratio, square_size=size)
40 else:
41 image = cv2.resize(
42 src=image,
43 dsize=(size, size),
44 interpolation=cv2.INTER_AREA,
45 )
46 return cv2.imwrite(save_path, image)
47
48 def step_rembg(self, image_in: np.ndarray) -> np.ndarray:
49 image_out = rembg.remove(

Callers 3

preprocess_fnFunction · 0.45
preprocess_fnFunction · 0.45
preprocess_fnFunction · 0.45

Calls 4

step_load_to_sizeMethod · 0.95
step_rembgMethod · 0.95
step_recenterMethod · 0.95
resizeMethod · 0.45

Tested by

no test coverage detected