Enhance image preprocessing documentation and clarify 3D model generation process. Update function docstrings to include detailed descriptions of input, output, and processing steps.
Browse files
app.py
CHANGED
@@ -36,28 +36,32 @@ pipeline.preprocess_image(Image.fromarray(np.zeros((512, 512, 3), dtype=np.uint8
|
|
36 |
|
37 |
|
38 |
def preprocess_image(image: Image.Image) -> Image.Image:
|
39 |
-
"""Preprocess the input image.
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
"""
|
47 |
-
return pipeline.preprocess_image(image)
|
48 |
-
|
49 |
-
|
50 |
-
def preprocess_images(images: list[tuple[Image.Image, str]]) -> list[Image.Image]:
|
51 |
-
"""Preprocess a list of input images.
|
52 |
|
53 |
Args:
|
54 |
-
|
55 |
|
56 |
Returns:
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
"""
|
59 |
-
|
60 |
-
return [pipeline.preprocess_image(image) for image in images]
|
61 |
|
62 |
|
63 |
def save_state_to_file(gs: Gaussian, mesh: MeshExtractResult, output_path: str) -> None:
|
@@ -118,6 +122,10 @@ def image_to_3d(
|
|
118 |
) -> tuple[str, str]:
|
119 |
"""Convert an image to a 3D model.
|
120 |
|
|
|
|
|
|
|
|
|
121 |
Args:
|
122 |
image (Image.Image): The input image.
|
123 |
seed (int): The random seed.
|
@@ -127,8 +135,13 @@ def image_to_3d(
|
|
127 |
slat_sampling_steps (int): The number of sampling steps for structured latent generation.
|
128 |
|
129 |
Returns:
|
130 |
-
str:
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
132 |
"""
|
133 |
outputs = pipeline.run(
|
134 |
image,
|
|
|
36 |
|
37 |
|
38 |
def preprocess_image(image: Image.Image) -> Image.Image:
|
39 |
+
"""Preprocess the input image for 3D model generation.
|
40 |
|
41 |
+
This function performs several preprocessing steps to prepare the image for 3D model generation:
|
42 |
+
1. Handles alpha channel or removes background if not present
|
43 |
+
2. Centers and crops the object
|
44 |
+
3. Normalizes the image size to 518x518 pixels
|
45 |
+
4. Applies proper alpha channel processing
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
Args:
|
48 |
+
image (Image.Image): The input image to be preprocessed. Can be either RGB or RGBA format.
|
49 |
|
50 |
Returns:
|
51 |
+
Image.Image: The preprocessed image with the following characteristics:
|
52 |
+
- Size: 518x518 pixels
|
53 |
+
- Format: RGBA
|
54 |
+
- Background: Removed
|
55 |
+
- Object: Centered and properly scaled
|
56 |
+
|
57 |
+
Raises:
|
58 |
+
None: This function does not raise any exceptions.
|
59 |
+
|
60 |
+
Note:
|
61 |
+
The preprocessing is handled by the pipeline's internal preprocessing function,
|
62 |
+
which uses rembg for background removal if needed.
|
63 |
"""
|
64 |
+
return pipeline.preprocess_image(image)
|
|
|
65 |
|
66 |
|
67 |
def save_state_to_file(gs: Gaussian, mesh: MeshExtractResult, output_path: str) -> None:
|
|
|
122 |
) -> tuple[str, str]:
|
123 |
"""Convert an image to a 3D model.
|
124 |
|
125 |
+
This function takes an input image and generates a 3D model using a two-stage process
|
126 |
+
with separate parameters for each stage. It also generates a preview video that combines
|
127 |
+
color and normal map renderings of the 3D model.
|
128 |
+
|
129 |
Args:
|
130 |
image (Image.Image): The input image.
|
131 |
seed (int): The random seed.
|
|
|
135 |
slat_sampling_steps (int): The number of sampling steps for structured latent generation.
|
136 |
|
137 |
Returns:
|
138 |
+
tuple[str, str]: A tuple containing:
|
139 |
+
- str: Path to the state file (.pth) containing the 3D model data
|
140 |
+
- str: Path to the preview video file (.mp4) showing the 3D model rotation
|
141 |
+
|
142 |
+
Note:
|
143 |
+
The generated files are saved as temporary files that will not be automatically
|
144 |
+
deleted. It is the caller's responsibility to manage these files.
|
145 |
"""
|
146 |
outputs = pipeline.run(
|
147 |
image,
|