hsi-preprocessing-toolkit 2.0.0a2__tar.gz → 2.1.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-2.0.0a2 → hsi_preprocessing_toolkit-2.1.0}/PKG-INFO +26 -27
- {hsi_preprocessing_toolkit-2.0.0a2 → hsi_preprocessing_toolkit-2.1.0}/README.md +20 -20
- {hsi_preprocessing_toolkit-2.0.0a2 → hsi_preprocessing_toolkit-2.1.0}/pyproject.toml +7 -8
- hsi_preprocessing_toolkit-2.1.0/src/hsi_preprocessing_toolkit/__main__.py +29 -0
- {hsi_preprocessing_toolkit-2.0.0a2 → hsi_preprocessing_toolkit-2.1.0}/src/hsi_preprocessing_toolkit/algorithm.py +3 -7
- hsi_preprocessing_toolkit-2.1.0/src/hsi_preprocessing_toolkit/asset/page/about.en.md +31 -0
- hsi_preprocessing_toolkit-2.1.0/src/hsi_preprocessing_toolkit/asset/page/about.zh.md +33 -0
- hsi_preprocessing_toolkit-2.1.0/src/hsi_preprocessing_toolkit/common.py +137 -0
- hsi_preprocessing_toolkit-2.1.0/src/hsi_preprocessing_toolkit/component/create_logger.py +39 -0
- hsi_preprocessing_toolkit-2.1.0/src/hsi_preprocessing_toolkit/component/logging_box.py +43 -0
- hsi_preprocessing_toolkit-2.1.0/src/hsi_preprocessing_toolkit/page/about.py +35 -0
- hsi_preprocessing_toolkit-2.1.0/src/hsi_preprocessing_toolkit/page/hsi_preprocessing.py +624 -0
- hsi_preprocessing_toolkit-2.1.0/src/hsi_preprocessing_toolkit/page/scanner_calc.py +53 -0
- hsi_preprocessing_toolkit-2.1.0/src/hsi_preprocessing_toolkit/util.py +31 -0
- hsi_preprocessing_toolkit-2.0.0a2/src/hsi_preprocessing_toolkit/__main__.py +0 -615
- hsi_preprocessing_toolkit-2.0.0a2/src/hsi_preprocessing_toolkit/i18n.py +0 -78
- hsi_preprocessing_toolkit-2.0.0a2/src/hsi_preprocessing_toolkit/page/scanner_calc.py +0 -54
- {hsi_preprocessing_toolkit-2.0.0a2 → hsi_preprocessing_toolkit-2.1.0}/src/hsi_preprocessing_toolkit/__init__.py +0 -0
- {hsi_preprocessing_toolkit-2.0.0a2 → hsi_preprocessing_toolkit-2.1.0}/src/hsi_preprocessing_toolkit/asset/icon.ico +0 -0
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hsi-preprocessing-toolkit
|
|
3
|
-
Version: 2.0
|
|
3
|
+
Version: 2.1.0
|
|
4
4
|
Summary: HSI Preprocessing Toolkit
|
|
5
5
|
Author: songyz2023
|
|
6
6
|
Author-email: songyz2023 <songyz2023dlut@outlook.com>
|
|
7
7
|
License-Expression: AGPL-3.0-only
|
|
8
8
|
Classifier: Programming Language :: Python
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
10
9
|
Classifier: Programming Language :: Python :: 3.13
|
|
11
10
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
12
|
-
Requires-Dist: einops>=0.8.
|
|
13
|
-
Requires-Dist: gradio>=5.
|
|
14
|
-
Requires-Dist: matplotlib>=3.10.
|
|
15
|
-
Requires-Dist: rasterio>=1.4.
|
|
11
|
+
Requires-Dist: einops>=0.8.0
|
|
12
|
+
Requires-Dist: gradio>=5.50.0,<6.0.0
|
|
13
|
+
Requires-Dist: matplotlib>=3.10.0
|
|
14
|
+
Requires-Dist: rasterio>=1.4.0
|
|
16
15
|
Requires-Dist: rs-fusion-datasets>=0.16.0
|
|
17
|
-
Requires-Dist: scipy>=1.
|
|
16
|
+
Requires-Dist: scipy>=1.16.0
|
|
18
17
|
Requires-Python: >=3.13
|
|
19
18
|
Project-URL: Documentation, https://github.com/songyz2019/hsi-preprocessing-toolkit#readme
|
|
20
19
|
Project-URL: Issues, https://github.com/songyz2019/hsi-preprocessing-toolkit/issues
|
|
@@ -23,8 +22,6 @@ Description-Content-Type: text/markdown
|
|
|
23
22
|
|
|
24
23
|
# HSI Preprocessing Toolkit
|
|
25
24
|
|
|
26
|
-

|
|
27
|
-
|
|
28
25
|
|
|
29
26
|
[](https://pypi.org/project/hsi-preprocessing-toolkit)
|
|
30
27
|
[](https://pypi.org/project/hsi-preprocessing-toolkit)
|
|
@@ -32,36 +29,38 @@ Description-Content-Type: text/markdown
|
|
|
32
29
|

|
|
33
30
|

|
|
34
31
|
|
|
32
|
+

|
|
35
33
|
|
|
36
|
-
|
|
34
|
+
HSI Preprocessing Toolkit (HPT, formerly HDR2MAT) is a hyperspectral image preprocessing toolset that:
|
|
37
35
|
1. Read the raw data from the HSI camera, and convert it into `.mat` file
|
|
38
36
|
2. Read the `.mat` file
|
|
39
37
|
3. Preview HSI, and convert it to RGB `.png` file
|
|
40
38
|
4. Crop and rotate the HSI and preview in realtime
|
|
41
39
|
5. Select spectrals of interest visually and save them into a `.mat` file
|
|
42
|
-
6. Mix multiple HSI
|
|
40
|
+
6. Mix multiple HSI images with layers.
|
|
41
|
+
7. Some other utils
|
|
43
42
|
|
|
44
43
|
|
|
45
44
|
## Usage
|
|
46
45
|
### Manual
|
|
47
|
-
1. Download from GitHub release
|
|
48
|
-
2. Double click the `
|
|
46
|
+
1. Download [hpt.cmd](https://github.com/songyz2019/hsi-preprocessing-toolkit/blob/main/script/hpt.cmd) from GitHub release
|
|
47
|
+
2. Double click the `hpt.cmd` file.
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
```sh
|
|
52
|
-
pip install hsi-preprocessing-toolkit
|
|
53
|
-
hsi_preprocessing_toolkit
|
|
54
|
-
```
|
|
49
|
+
> **TIPS**: Make sure you have internet access during the first start
|
|
55
50
|
|
|
56
51
|
### Install with uv
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
hsi_preprocessing_toolkit
|
|
64
|
-
|
|
52
|
+
1. Install [uv](https://docs.astral.sh/uv/) directly or with pip: `pip install uv`
|
|
53
|
+
2. Install HPT: `uv tool install hsi-preprocessing-toolkit`
|
|
54
|
+
3. Start HPT: `hsi_preprocessing_toolkit`
|
|
55
|
+
|
|
56
|
+
### Install with pip
|
|
57
|
+
1. Install HPT: `pip install hsi-preprocessing-toolkit`
|
|
58
|
+
2. Start HPT: `hsi_preprocessing_toolkit`
|
|
59
|
+
|
|
60
|
+
> **TIPS**: It's not recommend to install CLI tools directly with pip, please use [uv tool](https://docs.astral.sh/uv/guides/tools/) or [pipx](https://pipx.pypa.io/) to install python applications in isolated environments.
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
## Document
|
|
65
64
|
|
|
66
65
|
|
|
67
66
|
## Credit
|
|
@@ -89,4 +88,4 @@ GNU Affero General Public License for more details.
|
|
|
89
88
|
|
|
90
89
|
You should have received a copy of the GNU Affero General Public License
|
|
91
90
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
92
|
-
```
|
|
91
|
+
```
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# HSI Preprocessing Toolkit
|
|
2
2
|
|
|
3
|
-

|
|
4
|
-
|
|
5
3
|
|
|
6
4
|
[](https://pypi.org/project/hsi-preprocessing-toolkit)
|
|
7
5
|
[](https://pypi.org/project/hsi-preprocessing-toolkit)
|
|
@@ -9,36 +7,38 @@
|
|
|
9
7
|

|
|
10
8
|

|
|
11
9
|
|
|
10
|
+

|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
HSI Preprocessing Toolkit (HPT, formerly HDR2MAT) is a hyperspectral image preprocessing toolset that:
|
|
14
13
|
1. Read the raw data from the HSI camera, and convert it into `.mat` file
|
|
15
14
|
2. Read the `.mat` file
|
|
16
15
|
3. Preview HSI, and convert it to RGB `.png` file
|
|
17
16
|
4. Crop and rotate the HSI and preview in realtime
|
|
18
17
|
5. Select spectrals of interest visually and save them into a `.mat` file
|
|
19
|
-
6. Mix multiple HSI
|
|
18
|
+
6. Mix multiple HSI images with layers.
|
|
19
|
+
7. Some other utils
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
## Usage
|
|
23
23
|
### Manual
|
|
24
|
-
1. Download from GitHub release
|
|
25
|
-
2. Double click the `
|
|
24
|
+
1. Download [hpt.cmd](https://github.com/songyz2019/hsi-preprocessing-toolkit/blob/main/script/hpt.cmd) from GitHub release
|
|
25
|
+
2. Double click the `hpt.cmd` file.
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
```sh
|
|
29
|
-
pip install hsi-preprocessing-toolkit
|
|
30
|
-
hsi_preprocessing_toolkit
|
|
31
|
-
```
|
|
27
|
+
> **TIPS**: Make sure you have internet access during the first start
|
|
32
28
|
|
|
33
29
|
### Install with uv
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
hsi_preprocessing_toolkit
|
|
41
|
-
|
|
30
|
+
1. Install [uv](https://docs.astral.sh/uv/) directly or with pip: `pip install uv`
|
|
31
|
+
2. Install HPT: `uv tool install hsi-preprocessing-toolkit`
|
|
32
|
+
3. Start HPT: `hsi_preprocessing_toolkit`
|
|
33
|
+
|
|
34
|
+
### Install with pip
|
|
35
|
+
1. Install HPT: `pip install hsi-preprocessing-toolkit`
|
|
36
|
+
2. Start HPT: `hsi_preprocessing_toolkit`
|
|
37
|
+
|
|
38
|
+
> **TIPS**: It's not recommend to install CLI tools directly with pip, please use [uv tool](https://docs.astral.sh/uv/guides/tools/) or [pipx](https://pipx.pypa.io/) to install python applications in isolated environments.
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Document
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
## Credit
|
|
@@ -66,4 +66,4 @@ GNU Affero General Public License for more details.
|
|
|
66
66
|
|
|
67
67
|
You should have received a copy of the GNU Affero General Public License
|
|
68
68
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
69
|
-
```
|
|
69
|
+
```
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "hsi-preprocessing-toolkit"
|
|
3
|
-
version = "2.0.
|
|
3
|
+
version = "2.1.0" # This will be changed by dunami according to git tag when releasing.
|
|
4
4
|
description = "HSI Preprocessing Toolkit"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.13"
|
|
7
7
|
dependencies = [
|
|
8
|
-
"einops>=0.8.
|
|
9
|
-
"gradio>=5.
|
|
10
|
-
"matplotlib>=3.10.
|
|
11
|
-
"rasterio>=1.4.
|
|
8
|
+
"einops>=0.8.0",
|
|
9
|
+
"gradio>=5.50.0,<6.0.0",
|
|
10
|
+
"matplotlib>=3.10.0",
|
|
11
|
+
"rasterio>=1.4.0",
|
|
12
12
|
"rs-fusion-datasets>=0.16.0",
|
|
13
|
-
"scipy>=1.
|
|
13
|
+
"scipy>=1.16.0",
|
|
14
14
|
]
|
|
15
15
|
authors = [
|
|
16
16
|
{ name = "songyz2023", email = "songyz2023dlut@outlook.com" },
|
|
17
17
|
]
|
|
18
18
|
classifiers = [
|
|
19
19
|
"Programming Language :: Python",
|
|
20
|
-
"Programming Language :: Python :: 3.12",
|
|
21
20
|
"Programming Language :: Python :: 3.13",
|
|
22
21
|
"Programming Language :: Python :: Implementation :: CPython",
|
|
23
22
|
]
|
|
@@ -33,7 +32,7 @@ url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"
|
|
|
33
32
|
default = true
|
|
34
33
|
|
|
35
34
|
[build-system]
|
|
36
|
-
requires = ["uv_build >= 0.
|
|
35
|
+
requires = ["uv_build >= 0.9.0, <0.10.0"]
|
|
37
36
|
build-backend = "uv_build"
|
|
38
37
|
|
|
39
38
|
[tool.hatch.build.targets.wheel]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import matplotlib.pyplot as plt
|
|
2
|
+
import gradio as gr
|
|
3
|
+
from .page.scanner_calc import ScannerCalcTab
|
|
4
|
+
from .page.about import AboutTab
|
|
5
|
+
from .page.hsi_preprocessing import HSIProcessingTab
|
|
6
|
+
from .component.create_logger import create_gr_logger
|
|
7
|
+
from .common import i18n, DEBUG, MULTI_USER, LOGGER_MEMORY_HANDLER, APP_NAME
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main():
|
|
11
|
+
# Global State
|
|
12
|
+
plt.rcParams['font.family'] = 'SimHei'
|
|
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=APP_NAME, theme=theme) as demo: # title=i18n("about.title")
|
|
19
|
+
HSIProcessingTab()
|
|
20
|
+
ScannerCalcTab()
|
|
21
|
+
AboutTab()
|
|
22
|
+
if not MULTI_USER:
|
|
23
|
+
create_gr_logger(LOGGER_MEMORY_HANDLER)
|
|
24
|
+
|
|
25
|
+
demo.launch(debug=DEBUG, share=False, inbrowser=True, i18n=i18n, favicon_path="asset/icon.ico") # , theme=theme
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
if __name__ == "__main__":
|
|
29
|
+
main()
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
from scipy.ndimage import rotate
|
|
2
2
|
import numpy as np
|
|
3
|
-
import logging
|
|
4
3
|
from copy import deepcopy
|
|
5
|
-
|
|
6
|
-
logging.basicConfig(level=logging.INFO)
|
|
7
|
-
logger = logging.getLogger(__name__)
|
|
8
|
-
logger.info("started")
|
|
4
|
+
from .common import LOGGER
|
|
9
5
|
|
|
10
6
|
# Return A HWC Image, the C should work with both RGB and HSI
|
|
11
7
|
def composite_img(imgs :list[np.ndarray], transforms:list[dict]):
|
|
12
8
|
imgs = deepcopy(imgs)
|
|
13
9
|
# Transform
|
|
14
|
-
|
|
10
|
+
LOGGER.info(f"{transforms=}")
|
|
15
11
|
for i, (img,trans) in enumerate(zip(imgs, transforms)):
|
|
16
12
|
rotate_deg = trans['rotation']
|
|
17
13
|
if rotate_deg % 360 != 0:
|
|
@@ -33,7 +29,7 @@ def composite_img(imgs :list[np.ndarray], transforms:list[dict]):
|
|
|
33
29
|
sizes = [ ((h+abs(x)),w+abs(y)) for (h,w,_),(x,y) in zip(shapes, offsets)]
|
|
34
30
|
canvas_h, canvas_w = ( max([x[0] for x in sizes]), max([x[1] for x in sizes]) )
|
|
35
31
|
canvas_shape = (canvas_h, canvas_w, canvas_c)
|
|
36
|
-
|
|
32
|
+
LOGGER.info(f"{sizes=} {canvas_shape=} {shapes=}")
|
|
37
33
|
canvas = np.zeros(shape=canvas_shape, dtype=imgs[0].dtype)
|
|
38
34
|
|
|
39
35
|
# 合成 Compositing
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Hyperspectral Preprocessing Toolkit
|
|
2
|
+
|
|
3
|
+
A Hyperspectral Image Preprocessing Toolkit from HSI Camera to Machine Learning Dataset.
|
|
4
|
+
|
|
5
|
+
## 帮助
|
|
6
|
+
- [Homepage](https://github.com/songyz2019/hsi-preprocessing-toolkit)
|
|
7
|
+
- [BUG Report](https://github.com/songyz2019/hsi-preprocessing-toolkit/issues)
|
|
8
|
+
- [Help](https://github.com/songyz2019/hsi-preprocessing-toolkit/wiki)
|
|
9
|
+
|
|
10
|
+
## Check for update
|
|
11
|
+

|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# License
|
|
16
|
+
```text
|
|
17
|
+
Copyright (C) 2025 songyz2019
|
|
18
|
+
|
|
19
|
+
This program is free software: you can redistribute it and/or modify
|
|
20
|
+
it under the terms of the GNU Affero General Public License as published by
|
|
21
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
22
|
+
(at your option) any later version.
|
|
23
|
+
|
|
24
|
+
This program is distributed in the hope that it will be useful,
|
|
25
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
26
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
27
|
+
GNU Affero General Public License for more details.
|
|
28
|
+
|
|
29
|
+
You should have received a copy of the GNU Affero General Public License
|
|
30
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
31
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Hyperspectral Preprocessing Toolkit
|
|
2
|
+
|
|
3
|
+
高光谱数据处理工具箱
|
|
4
|
+
|
|
5
|
+
## 帮助
|
|
6
|
+
- [主页](https://github.com/songyz2019/hsi-preprocessing-toolkit)
|
|
7
|
+
- [问题反馈](https://github.com/songyz2019/hsi-preprocessing-toolkit/issues)
|
|
8
|
+
- [帮助文档](https://github.com/songyz2019/hsi-preprocessing-toolkit/wiki)
|
|
9
|
+
|
|
10
|
+
## 检查更新
|
|
11
|
+

|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## 许可
|
|
16
|
+
```text
|
|
17
|
+
Copyright (C) 2025 songyz2019
|
|
18
|
+
|
|
19
|
+
This program is free software: you can redistribute it and/or modify
|
|
20
|
+
it under the terms of the GNU Affero General Public License as published by
|
|
21
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
22
|
+
(at your option) any later version.
|
|
23
|
+
|
|
24
|
+
This program is distributed in the hope that it will be useful,
|
|
25
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
26
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
27
|
+
GNU Affero General Public License for more details.
|
|
28
|
+
|
|
29
|
+
You should have received a copy of the GNU Affero General Public License
|
|
30
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import gradio as gr
|
|
2
|
+
import logging
|
|
3
|
+
import logging.handlers
|
|
4
|
+
import os
|
|
5
|
+
import importlib.metadata
|
|
6
|
+
import platform
|
|
7
|
+
|
|
8
|
+
# 全局信息
|
|
9
|
+
APP_NAME='hsi-preprocessing-toolkit'
|
|
10
|
+
APP_VERSION = importlib.metadata.version(APP_NAME)
|
|
11
|
+
|
|
12
|
+
# 全局参数
|
|
13
|
+
DEBUG = os.environ.get('HPT_DEBUG','FALSE').upper() in ['1', 'TRUE', 'YES']
|
|
14
|
+
MULTI_USER = os.environ.get('HPT_MULTI_USER','FALSE').upper() in ['1', 'TRUE', 'YES']
|
|
15
|
+
|
|
16
|
+
# I18N
|
|
17
|
+
TRANSLATION = {
|
|
18
|
+
'en': {
|
|
19
|
+
"about.tab_title": "About",
|
|
20
|
+
"about.title": "HSI Preprocessing Toolkit",
|
|
21
|
+
|
|
22
|
+
"hsi_processing.tab_title": "HSI Processing",
|
|
23
|
+
"hsi_processing.load": "Load",
|
|
24
|
+
"hsi_processing.loading": "Loading, this could take minutes...",
|
|
25
|
+
"hsi_processing.loaded": "Loaded",
|
|
26
|
+
"hsi_processing.current_layer": "Selected Layer",
|
|
27
|
+
"hsi_processing.upload_instructions": "**Upload one of the following formats:**\n1. One .hdr file + one raw data file without extension\n2. One .mat file",
|
|
28
|
+
"hsi_processing.input_format": "Input Image Shape Format",
|
|
29
|
+
"hsi_processing.data_files": "Data Files",
|
|
30
|
+
"hsi_processing.manual_normalize": "Manual Normalize (affects preview only)",
|
|
31
|
+
"hsi_processing.normalize_min": "Normalize Min",
|
|
32
|
+
"hsi_processing.normalize_max": "Normalize Max",
|
|
33
|
+
"hsi_processing.wavelength_start": "Wavelength Range Start",
|
|
34
|
+
"hsi_processing.wavelength_end": "Wavelength Range End",
|
|
35
|
+
"hsi_processing.processing": "Processing",
|
|
36
|
+
"hsi_processing.crop": "Crop",
|
|
37
|
+
"hsi_processing.top": "Top",
|
|
38
|
+
"hsi_processing.bottom": "Bottom",
|
|
39
|
+
"hsi_processing.left": "Left",
|
|
40
|
+
"hsi_processing.right": "Right",
|
|
41
|
+
"hsi_processing.rotate": "Rotate",
|
|
42
|
+
"hsi_processing.rotate_degree": "Rotate Degree",
|
|
43
|
+
"hsi_processing.translate_offset": "Traslate",
|
|
44
|
+
"hsi_processing.translate_x": "X",
|
|
45
|
+
"hsi_processing.translate_y": "Y",
|
|
46
|
+
"hsi_processing.preview": "Preview",
|
|
47
|
+
"hsi_processing.apply_processing": "Apply Processing Effects",
|
|
48
|
+
"hsi_processing.mat_data_type": "MAT Data Type",
|
|
49
|
+
"hsi_processing.mat_format": "MAT Image Shape Format",
|
|
50
|
+
"hsi_processing.mat_key": "Key of MAT file",
|
|
51
|
+
"hsi_processing.compress_mat": "Produce Compressed MAT File",
|
|
52
|
+
"hsi_processing.spectral_selection": "Spectral Selection",
|
|
53
|
+
"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.",
|
|
54
|
+
"hsi_processing.spectral_plot": "Spectral Plot",
|
|
55
|
+
"hsi_processing.style": "Style",
|
|
56
|
+
"hsi_processing.clear": "Clear",
|
|
57
|
+
"hsi_processing.download": "Download",
|
|
58
|
+
"hsi_processing.output_results": "Output Results",
|
|
59
|
+
"hsi_processing.mat_file": "MAT File",
|
|
60
|
+
"hsi_processing.info": "Info",
|
|
61
|
+
"hsi_processing.same_as_input": "Same",
|
|
62
|
+
"hsi_processing.auto_detect": "Auto Detect",
|
|
63
|
+
"hsi_processing.applying_transforms": "Applying Transforms...",
|
|
64
|
+
"hsi_processing.applied_transforms": "Transforms Done",
|
|
65
|
+
"hsi_processing.no_converted_data_for_clicking": "No transforms applied data, apply transforms first",
|
|
66
|
+
|
|
67
|
+
"scanner_calc.tab_title": "Scanner Parameters",
|
|
68
|
+
},
|
|
69
|
+
'zh-CN' : {
|
|
70
|
+
"about.tab_title": "关于",
|
|
71
|
+
"about.title": "HPT高光谱处理工具箱",
|
|
72
|
+
|
|
73
|
+
"hsi_processing.tab_title": "高光谱图像处理",
|
|
74
|
+
"hsi_processing.current_layer": "选中图层",
|
|
75
|
+
"hsi_processing.load": "加载",
|
|
76
|
+
"hsi_processing.loading": "加载中,这可能需要几分钟...",
|
|
77
|
+
"hsi_processing.loaded": "加载完成",
|
|
78
|
+
"hsi_processing.upload_instructions": "**应上传以下两种格式中的一种**\n1. 同时上传一个.hdr文件 + 一个无后缀的数据文件\n2. 一个.mat文件",
|
|
79
|
+
"hsi_processing.input_format": "输入数据形状",
|
|
80
|
+
"hsi_processing.data_files": "数据文件",
|
|
81
|
+
"hsi_processing.manual_normalize": "手动归一化(仅影响预览结果)",
|
|
82
|
+
"hsi_processing.normalize_min": "归一化最小值",
|
|
83
|
+
"hsi_processing.normalize_max": "归一化最大值",
|
|
84
|
+
"hsi_processing.wavelength_start": "波长范围起始",
|
|
85
|
+
"hsi_processing.wavelength_end": "波长范围结束",
|
|
86
|
+
"hsi_processing.processing": "处理",
|
|
87
|
+
"hsi_processing.crop": "裁切",
|
|
88
|
+
"hsi_processing.top": "上",
|
|
89
|
+
"hsi_processing.bottom": "下",
|
|
90
|
+
"hsi_processing.left": "左",
|
|
91
|
+
"hsi_processing.right": "右",
|
|
92
|
+
"hsi_processing.rotate": "旋转",
|
|
93
|
+
"hsi_processing.rotate_degree": "旋转角度",
|
|
94
|
+
"hsi_processing.translate_offset": "平移",
|
|
95
|
+
"hsi_processing.translate_x": "X轴",
|
|
96
|
+
"hsi_processing.translate_y": "Y轴",
|
|
97
|
+
"hsi_processing.preview": "预览",
|
|
98
|
+
"hsi_processing.apply_processing": "应用处理效果",
|
|
99
|
+
"hsi_processing.mat_data_type": "mat文件数据类型",
|
|
100
|
+
"hsi_processing.mat_format": "mat文件格式",
|
|
101
|
+
"hsi_processing.mat_key": "mat文件的key",
|
|
102
|
+
"hsi_processing.compress_mat": "启用mat文件压缩",
|
|
103
|
+
"hsi_processing.spectral_selection": "光谱选择",
|
|
104
|
+
"hsi_processing.spectral_selection_help": "点击预览图像图像中的像素进行光谱数据提取。选中的像素将在下方的光谱图中绘制。",
|
|
105
|
+
"hsi_processing.spectral_plot": "光谱图",
|
|
106
|
+
"hsi_processing.style": "样式",
|
|
107
|
+
"hsi_processing.clear": "清空",
|
|
108
|
+
"hsi_processing.download": "下载",
|
|
109
|
+
"hsi_processing.output_results": "输出结果",
|
|
110
|
+
"hsi_processing.mat_file": "MAT文件",
|
|
111
|
+
"hsi_processing.info": "信息",
|
|
112
|
+
"hsi_processing.same_as_input": "与输入相同",
|
|
113
|
+
"hsi_processing.auto_detect": "自动检测",
|
|
114
|
+
"hsi_processing.applying_transforms": "应用变换中...",
|
|
115
|
+
"hsi_processing.applied_transforms": "变换完成",
|
|
116
|
+
"hsi_processing.no_converted_data_for_clicking": "没有应用变换后的数据,请先应用变换",
|
|
117
|
+
|
|
118
|
+
"scanner_calc.tab_title": "推扫仪计算",
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
i18n = gr.I18n(**TRANSLATION)
|
|
122
|
+
|
|
123
|
+
# 日志
|
|
124
|
+
LOGGER = logging.getLogger(TRANSLATION['en']['about.title']) # 全局唯一LOGGER
|
|
125
|
+
LOGGER_MEMORY_HANDLER :logging.handlers.MemoryHandler|None = None
|
|
126
|
+
if not MULTI_USER:
|
|
127
|
+
LOGGER_MEMORY_HANDLER = logging.handlers.MemoryHandler(10_000, flushLevel=logging.WARNING) # 用于在UI中显示LOGGING信息
|
|
128
|
+
LOGGER.addHandler(LOGGER_MEMORY_HANDLER)
|
|
129
|
+
|
|
130
|
+
logging.basicConfig(
|
|
131
|
+
level=logging.DEBUG if DEBUG else logging.INFO,
|
|
132
|
+
format='[%(levelname)s %(asctime)s] %(name)s: %(message)s',
|
|
133
|
+
datefmt='%Y-%m-%d %H:%M:%S'
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
# 初始化完成
|
|
137
|
+
LOGGER.info(f"{APP_NAME} v{APP_VERSION} initalized. {DEBUG=} {MULTI_USER=} Gradio=v{gr.__version__} Python=v{platform.python_version()} OS={platform.platform()}")
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from ..util import records_to_html
|
|
2
|
+
import gradio as gr
|
|
3
|
+
import logging
|
|
4
|
+
# from functools import partial
|
|
5
|
+
|
|
6
|
+
# def _one_timer_tick(handler, state_n_line):
|
|
7
|
+
# n_line = len(handler.buffer)
|
|
8
|
+
# print(f"{n_line=} {state_n_line=}")
|
|
9
|
+
# if n_line == state_n_line:
|
|
10
|
+
# print("SKIP")
|
|
11
|
+
# return gr.skip(), state_n_line
|
|
12
|
+
# else:
|
|
13
|
+
# return gr.update(value=records_to_html(handler.buffer, with_pre_tag=True)), n_line
|
|
14
|
+
|
|
15
|
+
# Gradio 5.50中存在一个BUG,timer.tick中的show_progress="hidden"和gr.skip依然会触发loading动画,通过一个state来workaround
|
|
16
|
+
|
|
17
|
+
def create_gr_logger(handler :logging.handlers.MemoryHandler):
|
|
18
|
+
state_n_line = gr.State(0)
|
|
19
|
+
timer = gr.Timer(value=2)
|
|
20
|
+
html = gr.HTML(
|
|
21
|
+
value="Loading.....",
|
|
22
|
+
label='Logging',
|
|
23
|
+
show_label=True,
|
|
24
|
+
container=True,
|
|
25
|
+
min_height=50,
|
|
26
|
+
max_height=100,
|
|
27
|
+
)
|
|
28
|
+
state_n_line.change(
|
|
29
|
+
fn=lambda: records_to_html(handler.buffer, with_pre_tag=True),
|
|
30
|
+
inputs=[],
|
|
31
|
+
outputs=[html],
|
|
32
|
+
show_progress="hidden"
|
|
33
|
+
)
|
|
34
|
+
timer.tick(
|
|
35
|
+
fn=lambda: len(handler.buffer),
|
|
36
|
+
inputs=[],
|
|
37
|
+
outputs=[state_n_line],
|
|
38
|
+
show_progress="hidden"
|
|
39
|
+
)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# import gradio as gr
|
|
2
|
+
# import logging
|
|
3
|
+
# from collections import deque
|
|
4
|
+
|
|
5
|
+
# We assume that there're limited users. Since every user *SHOULD* have a copy of logging info in server.
|
|
6
|
+
# But actually, it is only creatd once when opening multiple tabs in browsers, wierd...
|
|
7
|
+
|
|
8
|
+
# class _DequeLogHandler(logging.Handler):
|
|
9
|
+
# def __init__(self, max_logging_lines: int):
|
|
10
|
+
# super().__init__()
|
|
11
|
+
# self.buffer = deque([], maxlen=max_logging_lines)
|
|
12
|
+
|
|
13
|
+
# def emit(self, record):
|
|
14
|
+
# msg = self.format(record)
|
|
15
|
+
# self.buffer.appendleft(msg) # Some how auto scroll not work :(, we have to use a upside-down logging textbox
|
|
16
|
+
|
|
17
|
+
# def get_logging(self, seprator='\n'):
|
|
18
|
+
# return seprator.join(self.buffer)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# def create_gr_logging_box(handler :logging.handlers.BufferingHandler, max_logging_lines=10_000, **kwargs) -> [logging.Handler, gr.Textbox]:
|
|
22
|
+
# # Somehow extend gr.Textbox block the UI, we do not wanna dive deeply, just a quick workaround
|
|
23
|
+
# """
|
|
24
|
+
# Usage:
|
|
25
|
+
# handler, widget = create_gr_logging() # with any kwargs for gr.Textbox you need
|
|
26
|
+
# logger.add_handler(handler)
|
|
27
|
+
|
|
28
|
+
# """
|
|
29
|
+
# kwargs |= {
|
|
30
|
+
# 'label': 'Logging',
|
|
31
|
+
# 'every': 0.5,
|
|
32
|
+
# 'buttons': ['copy'],
|
|
33
|
+
# 'lines': 10,
|
|
34
|
+
# 'max_lines': 10,
|
|
35
|
+
# 'autoscroll': False
|
|
36
|
+
# }
|
|
37
|
+
# textbox = gr.Textbox(
|
|
38
|
+
# value=lambda: handler.get_logging(),
|
|
39
|
+
# **kwargs
|
|
40
|
+
# )
|
|
41
|
+
|
|
42
|
+
# return handler, textbox
|
|
43
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import gradio as gr
|
|
2
|
+
from ..common import i18n, APP_VERSION
|
|
3
|
+
|
|
4
|
+
from importlib import resources
|
|
5
|
+
from string import Template
|
|
6
|
+
|
|
7
|
+
def load_about_md(lang :str):
|
|
8
|
+
if lang.startswith('zh'):
|
|
9
|
+
lang = 'zh'
|
|
10
|
+
else:
|
|
11
|
+
lang = 'en'
|
|
12
|
+
text = resources.files("hsi_preprocessing_toolkit.asset.page").joinpath(f"about.{lang}.md").read_text(encoding="utf-8")
|
|
13
|
+
return Template(text).safe_substitute(
|
|
14
|
+
VERSION=APP_VERSION
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
def AboutTab():
|
|
18
|
+
with gr.Tab(i18n('about.tab_title')):
|
|
19
|
+
# lang_state = gr.State()
|
|
20
|
+
|
|
21
|
+
# gr.HTML(
|
|
22
|
+
# "<script defer>document.querySelector('#language_holder').innerHTML=navigator.language;</script>",
|
|
23
|
+
# elem_id="language_holder",
|
|
24
|
+
# ).change(
|
|
25
|
+
# lambda x:x,
|
|
26
|
+
# outputs=lang_state
|
|
27
|
+
# )
|
|
28
|
+
about_content = gr.Markdown(load_about_md('zh') + '\n\n' + load_about_md('en'))
|
|
29
|
+
|
|
30
|
+
# lang_state.change(
|
|
31
|
+
# fn = load_about_md,
|
|
32
|
+
# inputs=[lang_state],
|
|
33
|
+
# outputs=[about_content]
|
|
34
|
+
# )
|
|
35
|
+
|