hsi-preprocessing-toolkit 1.1.4__tar.gz → 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hsi_preprocessing_toolkit-1.1.4 → hsi_preprocessing_toolkit-2.0.0}/PKG-INFO +4 -2
- {hsi_preprocessing_toolkit-1.1.4 → hsi_preprocessing_toolkit-2.0.0}/README.md +3 -1
- {hsi_preprocessing_toolkit-1.1.4 → hsi_preprocessing_toolkit-2.0.0}/pyproject.toml +2 -2
- hsi_preprocessing_toolkit-2.0.0/src/hsi_preprocessing_toolkit/__main__.py +28 -0
- hsi_preprocessing_toolkit-2.0.0/src/hsi_preprocessing_toolkit/algorithm.py +44 -0
- hsi_preprocessing_toolkit-2.0.0/src/hsi_preprocessing_toolkit/asset/icon.ico +0 -0
- hsi_preprocessing_toolkit-2.0.0/src/hsi_preprocessing_toolkit/constant.py +111 -0
- hsi_preprocessing_toolkit-2.0.0/src/hsi_preprocessing_toolkit/page/about.py +12 -0
- hsi_preprocessing_toolkit-2.0.0/src/hsi_preprocessing_toolkit/page/hsi_preprocessing.py +577 -0
- hsi_preprocessing_toolkit-2.0.0/src/hsi_preprocessing_toolkit/page/scanner_calc.py +53 -0
- hsi_preprocessing_toolkit-1.1.4/src/hsi_preprocessing_toolkit/__main__.py +0 -583
- hsi_preprocessing_toolkit-1.1.4/src/hsi_preprocessing_toolkit/scanner_calc.py +0 -38
- {hsi_preprocessing_toolkit-1.1.4 → hsi_preprocessing_toolkit-2.0.0}/src/hsi_preprocessing_toolkit/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hsi-preprocessing-toolkit
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.0.0
|
|
4
4
|
Summary: HSI Preprocessing Toolkit
|
|
5
5
|
Author: songyz2023
|
|
6
6
|
Author-email: songyz2023 <songyz2023dlut@outlook.com>
|
|
@@ -33,12 +33,14 @@ Description-Content-Type: text/markdown
|
|
|
33
33
|

|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
HSI Preprocessing Toolkit (HPT, formerly HDR2MAT) is a hyperspectral image preprocessing toolset that:
|
|
37
37
|
1. Read the raw data from the HSI camera, and convert it into `.mat` file
|
|
38
38
|
2. Read the `.mat` file
|
|
39
39
|
3. Preview HSI, and convert it to RGB `.png` file
|
|
40
40
|
4. Crop and rotate the HSI and preview in realtime
|
|
41
41
|
5. Select spectrals of interest visually and save them into a `.mat` file
|
|
42
|
+
6. Mix multiple HSI images with layers. (coming in v2.0.0)
|
|
43
|
+
7. Some other utils
|
|
42
44
|
|
|
43
45
|
|
|
44
46
|
## Usage
|
|
@@ -10,12 +10,14 @@
|
|
|
10
10
|

|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
HSI Preprocessing Toolkit (HPT, formerly HDR2MAT) is a hyperspectral image preprocessing toolset that:
|
|
14
14
|
1. Read the raw data from the HSI camera, and convert it into `.mat` file
|
|
15
15
|
2. Read the `.mat` file
|
|
16
16
|
3. Preview HSI, and convert it to RGB `.png` file
|
|
17
17
|
4. Crop and rotate the HSI and preview in realtime
|
|
18
18
|
5. Select spectrals of interest visually and save them into a `.mat` file
|
|
19
|
+
6. Mix multiple HSI images with layers. (coming in v2.0.0)
|
|
20
|
+
7. Some other utils
|
|
19
21
|
|
|
20
22
|
|
|
21
23
|
## Usage
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "hsi-preprocessing-toolkit"
|
|
3
|
-
version = "
|
|
3
|
+
version = "2.0.0"
|
|
4
4
|
description = "HSI Preprocessing Toolkit"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.13"
|
|
@@ -33,7 +33,7 @@ url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"
|
|
|
33
33
|
default = true
|
|
34
34
|
|
|
35
35
|
[build-system]
|
|
36
|
-
requires = ["uv_build >= 0.8.0, <0.
|
|
36
|
+
requires = ["uv_build >= 0.8.0, <0.10.0"]
|
|
37
37
|
build-backend = "uv_build"
|
|
38
38
|
|
|
39
39
|
[tool.hatch.build.targets.wheel]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import matplotlib.pyplot as plt
|
|
2
|
+
import gradio as gr
|
|
3
|
+
import gradio.utils
|
|
4
|
+
import logging
|
|
5
|
+
from .page.scanner_calc import scanner_calc_tab
|
|
6
|
+
from .page.about import about_tab
|
|
7
|
+
from .page.hsi_preprocessing import hsi_preprocessing_tab
|
|
8
|
+
from .constant import i18n
|
|
9
|
+
|
|
10
|
+
logging.basicConfig(level=logging.INFO)
|
|
11
|
+
|
|
12
|
+
def main():
|
|
13
|
+
theme = gr.themes.Default(primary_hue='cyan').set(
|
|
14
|
+
button_primary_background_fill='#39c5bb',
|
|
15
|
+
button_primary_background_fill_hover="#30A8A0",
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
with gr.Blocks(title="hsi-preprocessing-toolkit", theme=theme) as demo:
|
|
19
|
+
hsi_preprocessing_tab()
|
|
20
|
+
scanner_calc_tab()
|
|
21
|
+
about_tab()
|
|
22
|
+
|
|
23
|
+
demo.launch(share=False, inbrowser=True, i18n=i18n, favicon_path="asset/icon.ico")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
if __name__ == "__main__":
|
|
27
|
+
plt.rcParams['font.family'] = 'SimHei'
|
|
28
|
+
main()
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from scipy.ndimage import rotate
|
|
2
|
+
import numpy as np
|
|
3
|
+
import logging
|
|
4
|
+
from copy import deepcopy
|
|
5
|
+
|
|
6
|
+
logging.basicConfig(level=logging.INFO)
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
logger.info("started")
|
|
9
|
+
|
|
10
|
+
# Return A HWC Image, the C should work with both RGB and HSI
|
|
11
|
+
def composite_img(imgs :list[np.ndarray], transforms:list[dict]):
|
|
12
|
+
imgs = deepcopy(imgs)
|
|
13
|
+
# Transform
|
|
14
|
+
logger.info(f"{transforms=}")
|
|
15
|
+
for i, (img,trans) in enumerate(zip(imgs, transforms)):
|
|
16
|
+
rotate_deg = trans['rotation']
|
|
17
|
+
if rotate_deg % 360 != 0:
|
|
18
|
+
img = rotate(img, angle=rotate_deg, axes=(0, 1), reshape=True)
|
|
19
|
+
|
|
20
|
+
# Crop
|
|
21
|
+
crop_top, crop_left, crop_bottom, crop_right = trans['crop']
|
|
22
|
+
if crop_top > 0 or crop_left > 0 or crop_bottom > 0 or crop_right > 0:
|
|
23
|
+
crop_bottom = None if crop_bottom == 0 else -crop_bottom
|
|
24
|
+
crop_right = None if crop_right == 0 else -crop_right
|
|
25
|
+
img = img[crop_top:crop_bottom, crop_left:crop_right, :]
|
|
26
|
+
|
|
27
|
+
imgs[i] = img
|
|
28
|
+
|
|
29
|
+
# Caclate canvas size
|
|
30
|
+
shapes = [x.shape for x in imgs]
|
|
31
|
+
offsets = [ x['location'] for x in transforms ]
|
|
32
|
+
canvas_c = imgs[0].shape[-1]
|
|
33
|
+
sizes = [ ((h+abs(x)),w+abs(y)) for (h,w,_),(x,y) in zip(shapes, offsets)]
|
|
34
|
+
canvas_h, canvas_w = ( max([x[0] for x in sizes]), max([x[1] for x in sizes]) )
|
|
35
|
+
canvas_shape = (canvas_h, canvas_w, canvas_c)
|
|
36
|
+
logger.info(f"{sizes=} {canvas_shape=} {shapes=}")
|
|
37
|
+
canvas = np.zeros(shape=canvas_shape, dtype=imgs[0].dtype)
|
|
38
|
+
|
|
39
|
+
# 合成 Compositing
|
|
40
|
+
for img,trans in zip(imgs, transforms):
|
|
41
|
+
x,y = trans['location']
|
|
42
|
+
h,w,_ = img.shape
|
|
43
|
+
canvas[x:x+h, y:y+w] = img
|
|
44
|
+
return canvas
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import gradio as gr
|
|
2
|
+
|
|
3
|
+
CONSTS = dict(
|
|
4
|
+
homepage_url = "https://github.com/songyz2019/hsi-preprocessing-toolkit",
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
i18n = gr.I18n(**{
|
|
8
|
+
'en': {
|
|
9
|
+
"about.tab_title": "About",
|
|
10
|
+
"about.title": "HSI Preprocessing Toolkit",
|
|
11
|
+
"about.description": "A Hyperspectral Image Preprocessing Toolkit from HSI Camera to Machine Learning Dataset",
|
|
12
|
+
"about.homepage": "主页",
|
|
13
|
+
|
|
14
|
+
"hsi_processing.tab_title": "HSI Processing",
|
|
15
|
+
"hsi_processing.load": "Load",
|
|
16
|
+
"hsi_processing.upload_instructions": "**Upload one of the following formats:**\n1. One .hdr file + one raw data file without extension\n2. One .mat file",
|
|
17
|
+
"hsi_processing.input_format": "Input Image Shape Format",
|
|
18
|
+
"hsi_processing.data_files": "Data Files",
|
|
19
|
+
"hsi_processing.manual_normalize": "Manual Normalize (affects preview only)",
|
|
20
|
+
"hsi_processing.normalize_min": "Normalize Min",
|
|
21
|
+
"hsi_processing.normalize_max": "Normalize Max",
|
|
22
|
+
"hsi_processing.wavelength_start": "Wavelength Range Start",
|
|
23
|
+
"hsi_processing.wavelength_end": "Wavelength Range End",
|
|
24
|
+
"hsi_processing.processing": "Processing",
|
|
25
|
+
"hsi_processing.crop": "Crop",
|
|
26
|
+
"hsi_processing.top": "Top",
|
|
27
|
+
"hsi_processing.bottom": "Bottom",
|
|
28
|
+
"hsi_processing.left": "Left",
|
|
29
|
+
"hsi_processing.right": "Right",
|
|
30
|
+
"hsi_processing.rotate": "Rotate",
|
|
31
|
+
"hsi_processing.rotate_degree": "Rotate Degree",
|
|
32
|
+
"hsi_processing.preview": "Preview",
|
|
33
|
+
"hsi_processing.apply_processing": "Apply Processing Effects",
|
|
34
|
+
"hsi_processing.mat_data_type": "MAT Data Type",
|
|
35
|
+
"hsi_processing.mat_format": "MAT Image Shape Format",
|
|
36
|
+
"hsi_processing.mat_key": "Key of MAT file",
|
|
37
|
+
"hsi_processing.compress_mat": "Produce Compressed MAT File",
|
|
38
|
+
"hsi_processing.spectral_selection": "Spectral Selection",
|
|
39
|
+
"hsi_processing.spectral_selection_help": "Click on the image to select pixels for spectral data extraction. The selected pixels will be plotted in the spectral plot below.",
|
|
40
|
+
"hsi_processing.spectral_plot": "Spectral Plot",
|
|
41
|
+
"hsi_processing.style": "Style",
|
|
42
|
+
"hsi_processing.clear": "Clear",
|
|
43
|
+
"hsi_processing.download": "Download",
|
|
44
|
+
"hsi_processing.output_results": "Output Results",
|
|
45
|
+
"hsi_processing.mat_file": "MAT File",
|
|
46
|
+
"hsi_processing.info": "Info",
|
|
47
|
+
"hsi_processing.same_as_input": "Same",
|
|
48
|
+
"hsi_processing.auto_detect": "Auto Detect",
|
|
49
|
+
|
|
50
|
+
"scanner_calc.tab_title": "Scanner Parameters"
|
|
51
|
+
},
|
|
52
|
+
'zh-CN':{
|
|
53
|
+
"about.tab_title": "关于",
|
|
54
|
+
"about.title": "HPT高光谱处理工具箱",
|
|
55
|
+
"about.description": "A Hyperspectral Image Preprocessing Toolkit from HSI Camera to Machine Learning Dataset",
|
|
56
|
+
"about.homepage": "主页",
|
|
57
|
+
"about.license": """Copyright (C) 2025 songyz2019
|
|
58
|
+
|
|
59
|
+
This program is free software: you can redistribute it and/or modify
|
|
60
|
+
it under the terms of the GNU Affero General Public License as published by
|
|
61
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
62
|
+
(at your option) any later version.
|
|
63
|
+
|
|
64
|
+
This program is distributed in the hope that it will be useful,
|
|
65
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
66
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
67
|
+
GNU Affero General Public License for more details.
|
|
68
|
+
|
|
69
|
+
You should have received a copy of the GNU Affero General Public License
|
|
70
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.""",
|
|
71
|
+
|
|
72
|
+
"hsi_processing.tab_title": "高光谱图像处理",
|
|
73
|
+
"hsi_processing.load": "加载",
|
|
74
|
+
"hsi_processing.upload_instructions": "**应上传以下两种格式中的一种**\n1. 同时上传一个.hdr文件 + 一个无后缀的数据文件\n2. 一个.mat文件",
|
|
75
|
+
"hsi_processing.input_format": "输入数据形状",
|
|
76
|
+
"hsi_processing.data_files": "数据文件",
|
|
77
|
+
"hsi_processing.manual_normalize": "手动归一化(仅影响预览结果)",
|
|
78
|
+
"hsi_processing.normalize_min": "归一化最小值",
|
|
79
|
+
"hsi_processing.normalize_max": "归一化最大值",
|
|
80
|
+
"hsi_processing.wavelength_start": "波长范围起始",
|
|
81
|
+
"hsi_processing.wavelength_end": "波长范围结束",
|
|
82
|
+
"hsi_processing.processing": "处理",
|
|
83
|
+
"hsi_processing.crop": "裁切",
|
|
84
|
+
"hsi_processing.top": "上",
|
|
85
|
+
"hsi_processing.bottom": "下",
|
|
86
|
+
"hsi_processing.left": "左",
|
|
87
|
+
"hsi_processing.right": "右",
|
|
88
|
+
"hsi_processing.rotate": "旋转",
|
|
89
|
+
"hsi_processing.rotate_degree": "旋转角度",
|
|
90
|
+
"hsi_processing.preview": "预览",
|
|
91
|
+
"hsi_processing.apply_processing": "应用处理效果",
|
|
92
|
+
"hsi_processing.mat_data_type": "mat文件数据类型",
|
|
93
|
+
"hsi_processing.mat_format": "mat文件格式",
|
|
94
|
+
"hsi_processing.mat_key": "mat文件的key",
|
|
95
|
+
"hsi_processing.compress_mat": "启用mat文件压缩",
|
|
96
|
+
"hsi_processing.spectral_selection": "光谱选择",
|
|
97
|
+
"hsi_processing.spectral_selection_help": "点击预览图像图像中的像素进行光谱数据提取。选中的像素将在下方的光谱图中绘制。",
|
|
98
|
+
"hsi_processing.spectral_plot": "光谱图",
|
|
99
|
+
"hsi_processing.style": "样式",
|
|
100
|
+
"hsi_processing.clear": "清空",
|
|
101
|
+
"hsi_processing.download": "下载",
|
|
102
|
+
"hsi_processing.output_results": "输出结果",
|
|
103
|
+
"hsi_processing.mat_file": "MAT文件",
|
|
104
|
+
"hsi_processing.info": "信息",
|
|
105
|
+
"hsi_processing.same_as_input": "与输入相同",
|
|
106
|
+
"hsi_processing.auto_detect": "自动检测",
|
|
107
|
+
|
|
108
|
+
"scanner_calc.tab_title": "推扫仪计算"
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import gradio as gr
|
|
2
|
+
from ..constant import i18n, CONSTS
|
|
3
|
+
|
|
4
|
+
def about_tab():
|
|
5
|
+
with gr.Tab(i18n('about.tab_title')):
|
|
6
|
+
with gr.Column():
|
|
7
|
+
gr.Markdown('# ' + i18n('about.title'))
|
|
8
|
+
gr.Markdown(i18n('about.description'))
|
|
9
|
+
gr.Markdown(f"[{i18n('about.homepage')}]({CONSTS['homepage_url']})")
|
|
10
|
+
gr.Markdown("```text\n" + i18n('about.license') + "\n```")
|
|
11
|
+
|
|
12
|
+
|