MCPcopy Create free account
hub / github.com/chenfei-wu/TaskMatrix / inference

Method inference

visual_chatgpt.py:717–738  ·  view source on GitHub ↗
(self, inputs)

Source from the content-addressed store, hash-verified

715 "like: generate normal map from this image, or predict normal map of this image. "
716 "The input to this tool should be a string, representing the image_path")
717 def inference(self, inputs):
718 image = Image.open(inputs)
719 original_size = image.size
720 image = self.depth_estimator(image)['predicted_depth'][0]
721 image = image.numpy()
722 image_depth = image.copy()
723 image_depth -= np.min(image_depth)
724 image_depth /= np.max(image_depth)
725 x = cv2.Sobel(image, cv2.CV_32F, 1, 0, ksize=3)
726 x[image_depth < self.bg_threhold] = 0
727 y = cv2.Sobel(image, cv2.CV_32F, 0, 1, ksize=3)
728 y[image_depth < self.bg_threhold] = 0
729 z = np.ones_like(x) * np.pi * 2.0
730 image = np.stack([x, y, z], axis=2)
731 image /= np.sum(image ** 2.0, axis=2, keepdims=True) ** 0.5
732 image = (image * 127.5 + 127.5).clip(0, 255).astype(np.uint8)
733 image = Image.fromarray(image)
734 image = image.resize(original_size)
735 updated_image_path = get_new_image_name(inputs, func_name="normal-map")
736 image.save(updated_image_path)
737 print(f"\nProcessed Image2Normal, Input Image: {inputs}, Output Depth: {updated_image_path}")
738 return updated_image_path
739
740
741class NormalText2Image:

Callers

nothing calls this directly

Calls 1

get_new_image_nameFunction · 0.85

Tested by

no test coverage detected