Spaces:
Sleeping
Sleeping
Download demo/src/utils.py from andreped/AeroPath: direct link, hf CLI and curl.
- Browser
- Download file 861 Bytes
-
https://huggingface.co/spaces/andreped/AeroPath/resolve/main/demo/src/utils.py
- Command line
-
hf download hf://spaces/andreped/AeroPath/demo/src/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/andreped/AeroPath/resolve/main/demo/src/utils.py
861 Bytes
| import nibabel as nib | |
| import numpy as np | |
| def load_ct_to_numpy(data_path): | |
| if not isinstance(data_path, str): | |
| data_path = data_path.name | |
| image = nib.load(data_path) | |
| data = image.get_fdata() | |
| data = np.rot90(data, k=1, axes=(0, 1)) | |
| data[data < -1024] = 1024 | |
| data[data > 1024] = 1024 | |
| data = data - np.amin(data) | |
| data = data / np.amax(data) * 255 | |
| data = data.astype("uint8") | |
| print(data.shape) | |
| return [data[..., i] for i in range(data.shape[-1])] | |
| def load_pred_volume_to_numpy(data_path): | |
| if not isinstance(data_path, str): | |
| data_path = data_path.name | |
| image = nib.load(data_path) | |
| data = image.get_fdata() | |
| data = np.rot90(data, k=1, axes=(0, 1)) | |
| data[data > 0] = 1 | |
| data = data.astype("uint8") | |
| print(data.shape) | |
| return [data[..., i] for i in range(data.shape[-1])] | |