Add application file
Browse files
app.py
CHANGED
|
@@ -31,7 +31,7 @@ def readRAW(path):
|
|
| 31 |
|
| 32 |
return output
|
| 33 |
|
| 34 |
-
def load_bin(file):
|
| 35 |
raw_hist = readRAW(file.name)
|
| 36 |
|
| 37 |
multishot = (raw_hist[..., 254] * 1024 + raw_hist[..., 255]).astype(np.float32)
|
|
@@ -43,7 +43,7 @@ def load_bin(file):
|
|
| 43 |
img_uint8 = (norm_img * 255).astype(np.uint8)
|
| 44 |
img_zoomed = np.repeat(np.repeat(img_uint8, 4, axis=0), 4, axis=1)
|
| 45 |
|
| 46 |
-
depth_slider_imgs = plot_depth(nor_hist) # 👈 直接在这里计算
|
| 47 |
|
| 48 |
return img_zoomed, raw_hist, nor_hist, depth_slider_imgs
|
| 49 |
|
|
@@ -71,7 +71,7 @@ def to_uint8_image(arr):
|
|
| 71 |
norm = (arr) / (np.max(arr) + 1e-8)
|
| 72 |
return (norm * 255).astype(np.uint8)
|
| 73 |
|
| 74 |
-
def plot_depth(nor_hist):
|
| 75 |
kernel = np.ones((3,3))
|
| 76 |
output = np.zeros((96, 240, 254))
|
| 77 |
|
|
@@ -103,7 +103,7 @@ def plot_depth(nor_hist):
|
|
| 103 |
img_ref = to_uint8_image(ref)
|
| 104 |
img_ref_filter = to_uint8_image(ref_filter)
|
| 105 |
|
| 106 |
-
mask = ref>
|
| 107 |
# 转uint8图像方便展示
|
| 108 |
img_tof = to_uint8_image(tof)
|
| 109 |
img_filter = to_uint8_image(tof_filter)
|
|
@@ -123,7 +123,7 @@ with gr.Blocks() as demo:
|
|
| 123 |
image_display = gr.Image(interactive=True, label="点击像素显示强度曲线")
|
| 124 |
histogram = gr.Plot(label="像素强度曲线")
|
| 125 |
depth_image_slider = ImageSlider(label="Filter Depth Map with Slider View", elem_id='img-display-output', position=0.5)
|
| 126 |
-
|
| 127 |
|
| 128 |
raw_hist = gr.State()
|
| 129 |
nor_hist = gr.State()
|
|
@@ -131,7 +131,7 @@ with gr.Blocks() as demo:
|
|
| 131 |
# 单一入口统一触发
|
| 132 |
file_input.change(
|
| 133 |
load_bin,
|
| 134 |
-
inputs=file_input,
|
| 135 |
outputs=[image_display, raw_hist, nor_hist, depth_image_slider]
|
| 136 |
)
|
| 137 |
|
|
@@ -140,5 +140,10 @@ with gr.Blocks() as demo:
|
|
| 140 |
inputs=[raw_hist, nor_hist],
|
| 141 |
outputs=histogram
|
| 142 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
demo.launch()
|
|
|
|
| 31 |
|
| 32 |
return output
|
| 33 |
|
| 34 |
+
def load_bin(file, threshold=3):
|
| 35 |
raw_hist = readRAW(file.name)
|
| 36 |
|
| 37 |
multishot = (raw_hist[..., 254] * 1024 + raw_hist[..., 255]).astype(np.float32)
|
|
|
|
| 43 |
img_uint8 = (norm_img * 255).astype(np.uint8)
|
| 44 |
img_zoomed = np.repeat(np.repeat(img_uint8, 4, axis=0), 4, axis=1)
|
| 45 |
|
| 46 |
+
depth_slider_imgs = plot_depth(nor_hist,threshold) # 👈 直接在这里计算
|
| 47 |
|
| 48 |
return img_zoomed, raw_hist, nor_hist, depth_slider_imgs
|
| 49 |
|
|
|
|
| 71 |
norm = (arr) / (np.max(arr) + 1e-8)
|
| 72 |
return (norm * 255).astype(np.uint8)
|
| 73 |
|
| 74 |
+
def plot_depth(nor_hist,, threshold):
|
| 75 |
kernel = np.ones((3,3))
|
| 76 |
output = np.zeros((96, 240, 254))
|
| 77 |
|
|
|
|
| 103 |
img_ref = to_uint8_image(ref)
|
| 104 |
img_ref_filter = to_uint8_image(ref_filter)
|
| 105 |
|
| 106 |
+
mask = ref>threshold
|
| 107 |
# 转uint8图像方便展示
|
| 108 |
img_tof = to_uint8_image(tof)
|
| 109 |
img_filter = to_uint8_image(tof_filter)
|
|
|
|
| 123 |
image_display = gr.Image(interactive=True, label="点击像素显示强度曲线")
|
| 124 |
histogram = gr.Plot(label="像素强度曲线")
|
| 125 |
depth_image_slider = ImageSlider(label="Filter Depth Map with Slider View", elem_id='img-display-output', position=0.5)
|
| 126 |
+
threshold_slider = gr.Slider(1, 30, value=3, step=1, label="Mask 阈值设定 (ref > x)")
|
| 127 |
|
| 128 |
raw_hist = gr.State()
|
| 129 |
nor_hist = gr.State()
|
|
|
|
| 131 |
# 单一入口统一触发
|
| 132 |
file_input.change(
|
| 133 |
load_bin,
|
| 134 |
+
inputs=[file_input,threshold_slider],
|
| 135 |
outputs=[image_display, raw_hist, nor_hist, depth_image_slider]
|
| 136 |
)
|
| 137 |
|
|
|
|
| 140 |
inputs=[raw_hist, nor_hist],
|
| 141 |
outputs=histogram
|
| 142 |
)
|
| 143 |
+
threshold_slider.change(
|
| 144 |
+
load_bin,
|
| 145 |
+
inputs=[file_input,threshold_slider],
|
| 146 |
+
outputs=[image_display, raw_hist, nor_hist, depth_image_slider])
|
| 147 |
+
|
| 148 |
|
| 149 |
demo.launch()
|