mcp ready with good docstrings explanation
Browse files
app.py
CHANGED
@@ -112,7 +112,32 @@ def make_stereopair(left_img, right_img, color_method):
|
|
112 |
return np.array(pair)
|
113 |
|
114 |
def process_images(left_img, right_img, method, color_method):
|
115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
if method == "anaglyph":
|
117 |
return make_anaglyph(left_img, right_img, color_method)
|
118 |
elif method == "parallel":
|
@@ -134,31 +159,26 @@ with gr.Blocks(css=css) as app:
|
|
134 |
gr.Markdown("Upload left and right images to create 3D images using different methods.")
|
135 |
|
136 |
with gr.Row():
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
with gr.Column():
|
143 |
-
right_input = gr.Image(label="Right Image")
|
144 |
-
|
145 |
method = gr.Radio(
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
)
|
151 |
|
152 |
color_method = gr.Radio(
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
)
|
158 |
-
|
159 |
-
generate_btn = gr.Button("Generate 3D Image", variant="primary")
|
160 |
|
161 |
-
|
162 |
### Methods:
|
163 |
- **anaglyph**: Creates a red-cyan 3D image (requires 3D glasses)
|
164 |
- **parallel**: Creates side-by-side images for parallel viewing
|
@@ -170,9 +190,10 @@ with gr.Blocks(css=css) as app:
|
|
170 |
- **mono**: Monochrome output
|
171 |
- **color**: Full color (may cause ghosting)
|
172 |
- **halfcolor**: Balance between color and depth
|
173 |
-
|
174 |
-
|
175 |
-
|
|
|
176 |
|
177 |
generate_btn.click(
|
178 |
fn=process_images,
|
@@ -182,4 +203,4 @@ with gr.Blocks(css=css) as app:
|
|
182 |
|
183 |
# Launch the app
|
184 |
if __name__ == "__main__":
|
185 |
-
app.launch()
|
|
|
112 |
return np.array(pair)
|
113 |
|
114 |
def process_images(left_img, right_img, method, color_method):
|
115 |
+
|
116 |
+
"""Generate a 3D visualization from left and right stereo images.
|
117 |
+
|
118 |
+
This function processes a pair of stereo images (left and right views) and
|
119 |
+
generates a 3D image using the specified visualization method:
|
120 |
+
|
121 |
+
- "anaglyph": Combines the two images using a red-cyan color encoding, suitable
|
122 |
+
for viewing with 3D glasses.
|
123 |
+
- "parallel": Places the images side by side for stereoscopic viewing with the
|
124 |
+
parallel-eye method.
|
125 |
+
- "crossed": Similar to parallel, but with the left and right images swapped,
|
126 |
+
suitable for cross-eyed viewing.
|
127 |
+
|
128 |
+
You can also specify the color processing style (e.g., "optimized", "mono", "true", etc.)
|
129 |
+
for finer control over color blending or grayscale conversion.
|
130 |
+
|
131 |
+
Args:
|
132 |
+
left_img (numpy.ndarray): The left-eye image as a NumPy array.
|
133 |
+
right_img (numpy.ndarray): The right-eye image as a NumPy array.
|
134 |
+
method (str): The 3D generation method, one of: "anaglyph", "parallel", or "crossed".
|
135 |
+
color_method (str): The color matrix to use for processing. Options include: "optimized", "true", "mono", "color", "halfcolor", "dubois", "dubois_optimized".
|
136 |
+
|
137 |
+
Returns:
|
138 |
+
numpy.ndarray: The resulting 3D image, ready to be displayed or saved.
|
139 |
+
"""
|
140 |
+
|
141 |
if method == "anaglyph":
|
142 |
return make_anaglyph(left_img, right_img, color_method)
|
143 |
elif method == "parallel":
|
|
|
159 |
gr.Markdown("Upload left and right images to create 3D images using different methods.")
|
160 |
|
161 |
with gr.Row():
|
162 |
+
left_input = gr.Image(label="Left Image")
|
163 |
+
right_input = gr.Image(label="Right Image")
|
164 |
+
|
165 |
+
with gr.Row():
|
166 |
+
with gr.Column():
|
|
|
|
|
|
|
167 |
method = gr.Radio(
|
168 |
+
["anaglyph", "parallel", "crossed"],
|
169 |
+
label="Method",
|
170 |
+
value="anaglyph",
|
171 |
+
info="Select the 3D image creation method"
|
172 |
)
|
173 |
|
174 |
color_method = gr.Radio(
|
175 |
+
["optimized", "true", "mono", "color", "halfcolor", "dubois", "dubois_optimized"],
|
176 |
+
label="Color Method",
|
177 |
+
value="dubois",
|
178 |
+
info="Select the color processing method"
|
179 |
)
|
|
|
|
|
180 |
|
181 |
+
gr.Markdown("""
|
182 |
### Methods:
|
183 |
- **anaglyph**: Creates a red-cyan 3D image (requires 3D glasses)
|
184 |
- **parallel**: Creates side-by-side images for parallel viewing
|
|
|
190 |
- **mono**: Monochrome output
|
191 |
- **color**: Full color (may cause ghosting)
|
192 |
- **halfcolor**: Balance between color and depth
|
193 |
+
""")
|
194 |
+
|
195 |
+
generate_btn = gr.Button("Generate 3D Image", variant="primary")
|
196 |
+
output = gr.Image(label="Generated 3D Anaglyph Image")
|
197 |
|
198 |
generate_btn.click(
|
199 |
fn=process_images,
|
|
|
203 |
|
204 |
# Launch the app
|
205 |
if __name__ == "__main__":
|
206 |
+
app.launch(mcp_server=True)
|