Metadata-Version: 2.4
Name: neuron-process-utils
Version: 1.1.0
Summary: Neuron image/SWC utilities: SWC cleanup, mask/dist maps, nnU-Net prob export.
Author-email: jiang yan <1900812927@qq.com>
License: MIT License
        
        Copyright (c) 2025 还能热爱多久
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://gitee.com/Eason596/neuron-process-utils
Project-URL: Repository, https://gitee.com/Eason596/neuron-process-utils
Project-URL: Issues, https://gitee.com/Eason596/neuron-process-utils/issues
Keywords: neuron,swc,distance-map,nnunet
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Image Processing
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: swcgeom>=0.20.0
Requires-Dist: numpy
Requires-Dist: pandas
Requires-Dist: tifffile
Requires-Dist: scipy
Requires-Dist: tqdm
Provides-Extra: dev
Requires-Dist: black; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: pre-commit; extra == "dev"
Dynamic: license-file

# 神经元数据处理工具（npu）

图像与 SWC 需同名，例如 `1.tif` / `1.swc`。

## 安装

```shell
pip install neuron-process-utils
# 开发：
# pip install -e .
```

## 距离类型（`--dist-type` / `-t`）

| 类型 | 别名 | 含义 |
|------|------|------|
| `soft_centerline`（默认） | `neurolink` | NeuroLink 线性 soft：细骨架 EDT → `1 - D/d_M`（`d_M = lns/2`） |
| `sironi` | `soft_centerline_exp` | Sironi TPAMI 指数 soft：`exp(a(1-D/d_M))-1`（默认 `a=6`，峰值归一化到 `[0,1]`） |
| `pointtree` | `pointtree_log` / `segnet_log` | PointTree Seg_Net 代码：局部距离 → `-log` soft（`kernel_len=3`） |
| `pointtree_gaussian` | `segnet_gaussian` | PointTree 论文：Gaussian soft（`sigma=3`）再峰值归一化 |
| `inside_edt` | `tubular` | 实心管腔（用 SWC 半径）→ 前景内部 EDT（≈ 局部半径），背景为 0 |

后续新类型：在 `npu/distance.py` 的 `DIST_TYPE_REGISTRY` 注册即可。

## 命令

```shell
# 处理 SWC：orphan parent → -1，并从 1 连续编号
npu_swc_process -i ./CWMBS/swc
npu_swc_process -i ./CWMBS/swc -o ./CWMBS/process_swc

# SWC → mask（可用 -r 覆盖全部节点半径）
npu_swc_to_mask -i ./CWMBS/img -s ./CWMBS/process_swc -o ./CWMBS/process_mask
npu_swc_to_mask -i ./CWMBS/img -s ./CWMBS/process_swc -o ./CWMBS/process_mask -r 1

# SWC → dist（默认 soft_centerline，中间 mask 自动 r=1）
npu_swc_to_dist -i ./CWMBS/img -s ./CWMBS/process_swc -o ./CWMBS/process_dist
npu_swc_to_dist -i ./CWMBS/img -s ./CWMBS/process_swc -o ./CWMBS/process_dist -t soft_centerline --lns 10
npu_swc_to_dist -i ./CWMBS/img -s ./CWMBS/process_swc -o ./CWMBS/process_dist -t sironi --lns 10 --sironi-a 6
npu_swc_to_dist -i ./CWMBS/img -s ./CWMBS/process_swc -o ./CWMBS/process_dist -t pointtree --kernel-len 3
npu_swc_to_dist -i ./CWMBS/img -s ./CWMBS/process_swc -o ./CWMBS/process_dist -t pointtree_gaussian --sigma 3
npu_swc_to_dist -i ./CWMBS/img -s ./CWMBS/process_swc -o ./CWMBS/process_dist -t inside_edt
npu_swc_to_dist -i ./CWMBS/img -s ./CWMBS/process_swc -o ./CWMBS/process_dist -t inside_edt --normalize --uint8

# Mask → dist
npu_mask_to_dist -m ./CWMBS/process_mask -o ./CWMBS/process_dist
npu_mask_to_dist -m ./CWMBS/process_mask -o ./CWMBS/process_dist -t soft_centerline --lns 10
npu_mask_to_dist -m ./CWMBS/process_mask -o ./CWMBS/process_dist -t inside_edt --normalize

# nnUNet 概率图 .npz → tif
npu_nnunet_prob_to_tif -i ./preds -o ./preds_tif --uint8 -c 1
```

`--uint8`（旧旗标 `--s` 仍可用）将结果缩放到 `[0,255]` 存 uint8；默认 float32。
