Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -140,6 +140,7 @@ def extrude_depth_3d(
|
|
| 140 |
scene_lights=True,
|
| 141 |
prepare_for_3d_printing=False,
|
| 142 |
zip_outputs=False,
|
|
|
|
| 143 |
):
|
| 144 |
f_far_inner = -emboss
|
| 145 |
f_far_outer = f_far_inner - f_back
|
|
@@ -177,6 +178,7 @@ def extrude_depth_3d(
|
|
| 177 |
#depth_image_new[depth_image_new < 0] = 0
|
| 178 |
depth_image = median_filter(depth_image, size=filter_size)
|
| 179 |
depth_image = emboss*(depth_image - np.min(depth_image)) / (np.max(depth_image) - np.min(depth_image))
|
|
|
|
| 180 |
Image.fromarray((depth_image * 255).astype(np.uint8)).convert("L").save(path_out_base+".png")
|
| 181 |
rgb_image = np.array(
|
| 182 |
Image.open(path_rgb).convert("RGB").resize((w, h), Image.Resampling.LANCZOS)
|
|
@@ -427,7 +429,7 @@ def scale_to_width(img, length):
|
|
| 427 |
|
| 428 |
|
| 429 |
# Gradio Interface function
|
| 430 |
-
def process_image_and_generate_stl(image_input, depth_near, depth_far, thickness, alpha, backsheet):
|
| 431 |
# Depth Estimation
|
| 432 |
raw_img = cv2.imread(image_input)
|
| 433 |
depth = model.infer_image(raw_img) # HxW raw depth map in numpy
|
|
@@ -474,6 +476,7 @@ def process_image_and_generate_stl(image_input, depth_near, depth_far, thickness
|
|
| 474 |
vertex_colors=True,
|
| 475 |
scene_lights=True,
|
| 476 |
prepare_for_3d_printing=True,
|
|
|
|
| 477 |
)
|
| 478 |
|
| 479 |
return stl_path # Return the path to the generated STL file
|
|
@@ -488,7 +491,8 @@ iface = gr.Interface(
|
|
| 488 |
gr.Slider(minimum=0, maximum=1.0, value=1.0, label="Depth Far"),
|
| 489 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.3, label="Thickness"),
|
| 490 |
gr.Slider(minimum=0, maximum=1.0, value=0.05, label="Alpha"),
|
| 491 |
-
gr.Slider(minimum
|
|
|
|
| 492 |
],
|
| 493 |
outputs=gr.File(label="Download STL File"), # Use gr.File() for file downloads
|
| 494 |
title="Image to 2.5D Relief Model Generator",
|
|
|
|
| 140 |
scene_lights=True,
|
| 141 |
prepare_for_3d_printing=False,
|
| 142 |
zip_outputs=False,
|
| 143 |
+
lift_height=0.0
|
| 144 |
):
|
| 145 |
f_far_inner = -emboss
|
| 146 |
f_far_outer = f_far_inner - f_back
|
|
|
|
| 178 |
#depth_image_new[depth_image_new < 0] = 0
|
| 179 |
depth_image = median_filter(depth_image, size=filter_size)
|
| 180 |
depth_image = emboss*(depth_image - np.min(depth_image)) / (np.max(depth_image) - np.min(depth_image))
|
| 181 |
+
depth_image = np.where(depth_image != 0.0, depth_image + lift_height, 0.0)
|
| 182 |
Image.fromarray((depth_image * 255).astype(np.uint8)).convert("L").save(path_out_base+".png")
|
| 183 |
rgb_image = np.array(
|
| 184 |
Image.open(path_rgb).convert("RGB").resize((w, h), Image.Resampling.LANCZOS)
|
|
|
|
| 429 |
|
| 430 |
|
| 431 |
# Gradio Interface function
|
| 432 |
+
def process_image_and_generate_stl(image_input, depth_near, depth_far, thickness, alpha, backsheet, lift):
|
| 433 |
# Depth Estimation
|
| 434 |
raw_img = cv2.imread(image_input)
|
| 435 |
depth = model.infer_image(raw_img) # HxW raw depth map in numpy
|
|
|
|
| 476 |
vertex_colors=True,
|
| 477 |
scene_lights=True,
|
| 478 |
prepare_for_3d_printing=True,
|
| 479 |
+
lift_height=lift
|
| 480 |
)
|
| 481 |
|
| 482 |
return stl_path # Return the path to the generated STL file
|
|
|
|
| 491 |
gr.Slider(minimum=0, maximum=1.0, value=1.0, label="Depth Far"),
|
| 492 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.3, label="Thickness"),
|
| 493 |
gr.Slider(minimum=0, maximum=1.0, value=0.05, label="Alpha"),
|
| 494 |
+
gr.Slider(minimum=0.01, maximum=0.1, value=0.01, label="BackSheet Thickness")
|
| 495 |
+
gr.Slider(minimum=0, maximum=1.0, value=0.0, label="lift"),
|
| 496 |
],
|
| 497 |
outputs=gr.File(label="Download STL File"), # Use gr.File() for file downloads
|
| 498 |
title="Image to 2.5D Relief Model Generator",
|