Spaces:
Runtime error
Runtime error
Download src/design/forearm_shell.py from keinne/Pro_T_Transradial: direct link, hf CLI and curl.
- Browser
- Download file 864 Bytes
-
https://huggingface.co/spaces/keinne/Pro_T_Transradial/resolve/main/src/design/forearm_shell.py
- Command line
-
hf download hf://spaces/keinne/Pro_T_Transradial/src/design/forearm_shell.py
-
curl -L -o forearm_shell.py https://huggingface.co/spaces/keinne/Pro_T_Transradial/resolve/main/src/design/forearm_shell.py
864 Bytes
| import numpy as np | |
| from scipy import ndimage as ndi | |
| def build_forearm_shell_mask(seg_mask, spacing, dilation_mm=3.0): | |
| """ | |
| Gera uma máscara 3D representando a 'casca' do antebraço. | |
| - seg_mask: np.ndarray binária [Z,Y,X] | |
| - spacing: [sz, sy, sx] em mm | |
| - dilation_mm: expansão (mm) em torno da anatomia | |
| Retorna: np.ndarray binária [Z,Y,X] | |
| """ | |
| seg_mask = seg_mask.astype(bool) | |
| sp = float(np.mean(spacing)) | |
| vpm = 1.0 / max(sp, 1e-6) | |
| it = int(max(1, round(dilation_mm * vpm))) | |
| # Expande e suaviza a máscara para gerar a casca | |
| shell = ndi.binary_dilation(seg_mask, iterations=it) | |
| shell = ndi.binary_closing(shell, iterations=2) | |
| shell = ndi.binary_fill_holes(shell) | |
| shell = ndi.binary_opening(shell, iterations=1) | |
| shell = ndi.binary_closing(shell, iterations=1) | |
| return shell.astype(np.uint8) | |