JohnChiu commited on
Commit
6896642
·
1 Parent(s): a9b013c

Add application file

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  import numpy as np
3
  import plotly.graph_objs as go
4
  from scipy.ndimage import convolve
 
5
 
6
  def readRAW(path):
7
 
@@ -91,16 +92,61 @@ def plot_pixel_histogram(evt: gr.SelectData, raw_hist, nor_hist):
91
  return fig
92
 
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  with gr.Blocks() as demo:
95
  gr.Markdown("## 上传 96×240×256 int16 `.bin/.raw` 文件,点击图像像素查看该像素的 256 帧直方图")
96
 
97
  file_input = gr.File(label="上传 .raw/.bin 文件", file_types=[".raw", ".bin"])
98
  image_display = gr.Image(interactive=True, label="点击像素显示强度曲线")
 
 
 
 
 
99
  histogram = gr.Plot(label="像素强度曲线")
100
  raw_hist = gr.State()
101
  nor_hist = gr.State()
102
 
 
103
  file_input.change(load_bin, inputs=file_input, outputs=[image_display, raw_hist, nor_hist])
 
 
104
  image_display.select(plot_pixel_histogram, inputs=[ raw_hist, nor_hist], outputs=histogram)
105
 
106
  demo.launch()
 
2
  import numpy as np
3
  import plotly.graph_objs as go
4
  from scipy.ndimage import convolve
5
+ from gradio_imageslider import ImageSlider
6
 
7
  def readRAW(path):
8
 
 
92
  return fig
93
 
94
 
95
+ def to_uint8_image(arr):
96
+ norm = (arr - arr.min()) / (arr.ptp() + 1e-8)
97
+ return (norm * 255).astype(np.uint8)
98
+
99
+ def plot_depth(nor_hist):
100
+ kernel = np.ones((3,3))
101
+ output = np.zeros((96, 240, 254))
102
+
103
+ for i in range(254):
104
+ output[:, :, i] = convolve(nor_hist[:, :, i], kernel, mode='constant', cval=0)
105
+
106
+ modulate1 = np.arange(1, 181)
107
+ modulate = (modulate1 * modulate1) / (180 * 180)
108
+
109
+ arr = output[:, :, :180] * modulate[np.newaxis, np.newaxis, :]
110
+
111
+ tc_bin = np.sum(arr, axis=(0,1))
112
+ max_id = np.argmax(tc_bin[:-2])
113
+
114
+ pad_head = np.ones(max_id - 4)
115
+ expand_kernel = np.arange(1, 13) * 0.01
116
+ pad_tail = np.ones(180 - len(pad_head) - len(expand_kernel))
117
+ expand_filter = np.concatenate([pad_head, expand_kernel, pad_tail])
118
+
119
+ arr_expandfilter = arr * expand_filter[np.newaxis, np.newaxis, :]
120
+
121
+ tof = np.argmax(arr, axis=2)
122
+ tof_filter = np.argmax(arr_expandfilter, axis=2)
123
+
124
+
125
+ # 转uint8图像方便展示
126
+ img_tof = to_uint8_image(tof)
127
+ img_filter = to_uint8_image(tof_filter)
128
+
129
+ return [(img_tof, img_filter)]
130
+
131
+
132
  with gr.Blocks() as demo:
133
  gr.Markdown("## 上传 96×240×256 int16 `.bin/.raw` 文件,点击图像像素查看该像素的 256 帧直方图")
134
 
135
  file_input = gr.File(label="上传 .raw/.bin 文件", file_types=[".raw", ".bin"])
136
  image_display = gr.Image(interactive=True, label="点击像素显示强度曲线")
137
+
138
+ depth_image_slider = ImageSlider(label="Filter Depth Map with Slider View", elem_id='img-display-output', position=0.5,)
139
+
140
+
141
+
142
  histogram = gr.Plot(label="像素强度曲线")
143
  raw_hist = gr.State()
144
  nor_hist = gr.State()
145
 
146
+
147
  file_input.change(load_bin, inputs=file_input, outputs=[image_display, raw_hist, nor_hist])
148
+ file_input.change(plot_depth, inputs=nor_hist, outputs=[depth_image_slider])
149
+
150
  image_display.select(plot_pixel_histogram, inputs=[ raw_hist, nor_hist], outputs=histogram)
151
 
152
  demo.launch()