JohnChiu commited on
Commit
760b53b
·
1 Parent(s): 18b0f3c

Add application file

Browse files
Files changed (1) hide show
  1. app.py +26 -27
app.py CHANGED
@@ -5,6 +5,31 @@ from scipy.ndimage import convolve
5
  from gradio_imageslider import ImageSlider
6
  import cv2
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  def load_bin(file):
10
  raw_hist = readRAW(file.name)
@@ -75,39 +100,13 @@ def plot_depth(nor_hist):
75
  mask = ref>3
76
  # 转uint8图像方便展示
77
  img_tof = to_uint8_image(tof)
78
- img_filter = to_uint8_image(tof_filter) * mask
79
 
80
  colored_tof = cv2.applyColorMap(img_tof, cv2.COLORMAP_VIRIDIS)[:, :, ::-1]
81
  colored_tof_filter = cv2.applyColorMap(img_filter, cv2.COLORMAP_VIRIDIS)[:, :, ::-1]
82
 
83
  return [colored_tof, colored_tof_filter]
84
 
85
- def readRAW(path):
86
-
87
- arr = np.fromfile(path, dtype=np.int16).reshape(96,240,256)
88
- # 将最后一维重塑为 (-1, 2),其中 -1 自动计算为 128
89
- reshaped = arr.reshape(*arr.shape[:-1], -1, 2)
90
- # 交换每一对中的两个元素
91
- swapped = reshaped[..., :, ::-1]
92
- # 恢复原始形状
93
- histogram_data = swapped.reshape(arr.shape)
94
- # 定义映射顺序:对每组8行进行调换
95
- mapping = [0, 4, 1, 5, 2, 6, 3, 7]
96
- # 每组包含的行数
97
- group_size = 8
98
- num_groups = 12 # 96/8
99
-
100
- # 创建一个用于存储结果的数组(也可以原地修改)
101
- output = np.empty_like(histogram_data)
102
-
103
- # 对每个 group 分别进行行重排
104
- for g in range(num_groups):
105
- start = g * group_size
106
- end = start + group_size
107
- output[start:end,:,:] = histogram_data[start:end,:,:][mapping,:,:]
108
-
109
- return output
110
-
111
 
112
  with gr.Blocks() as demo:
113
  gr.Markdown("## 上传 96×240×256 int16 `.bin/.raw` 文件,点击图像像素查看该像素的 256 帧直方图")
 
5
  from gradio_imageslider import ImageSlider
6
  import cv2
7
 
8
+ def readRAW(path):
9
+
10
+ arr = np.fromfile(path, dtype=np.int16).reshape(96,240,256)
11
+ # 将最后一维重塑为 (-1, 2),其中 -1 自动计算为 128
12
+ reshaped = arr.reshape(*arr.shape[:-1], -1, 2)
13
+ # 交换每一对中的两个元素
14
+ swapped = reshaped[..., :, ::-1]
15
+ # 恢复原始形状
16
+ histogram_data = swapped.reshape(arr.shape)
17
+ # 定义映射顺序:对每组8行进行调换
18
+ mapping = [0, 4, 1, 5, 2, 6, 3, 7]
19
+ # 每组包含的行数
20
+ group_size = 8
21
+ num_groups = 12 # 96/8
22
+
23
+ # 创建一个用于存储结果的数组(也可以原地修改)
24
+ output = np.empty_like(histogram_data)
25
+
26
+ # 对每个 group 分别进行行重排
27
+ for g in range(num_groups):
28
+ start = g * group_size
29
+ end = start + group_size
30
+ output[start:end,:,:] = histogram_data[start:end,:,:][mapping,:,:]
31
+
32
+ return output
33
 
34
  def load_bin(file):
35
  raw_hist = readRAW(file.name)
 
100
  mask = ref>3
101
  # 转uint8图像方便展示
102
  img_tof = to_uint8_image(tof)
103
+ img_filter = to_uint8_image(tof_filter)
104
 
105
  colored_tof = cv2.applyColorMap(img_tof, cv2.COLORMAP_VIRIDIS)[:, :, ::-1]
106
  colored_tof_filter = cv2.applyColorMap(img_filter, cv2.COLORMAP_VIRIDIS)[:, :, ::-1]
107
 
108
  return [colored_tof, colored_tof_filter]
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
  with gr.Blocks() as demo:
112
  gr.Markdown("## 上传 96×240×256 int16 `.bin/.raw` 文件,点击图像像素查看该像素的 256 帧直方图")