Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resources showing programmatic segmentation using available models #52

Closed
mattwarkentin opened this issue Apr 24, 2024 · 5 comments
Closed

Comments

@mattwarkentin
Copy link

Hi,

Maybe I've been looking in the wrong spots, but are there any scripts/resources showing how to programmatically perform segmentation in Python rather than the Slicer UI using one of the available models? Thanks.

@lassoan
Copy link
Owner

lassoan commented Apr 24, 2024

Here is the inference script: https://github.com/lassoan/SlicerMONAIAuto3DSeg/blob/main/MONAIAuto3DSeg/Scripts/auto3dseg_segresnet_inference.py

@lassoan lassoan closed this as completed Apr 24, 2024
@mattwarkentin
Copy link
Author

Thanks, Andras!

@diazandr3s
Copy link
Collaborator

Hi @mattwarkentin,

Very good question. Thanks for asking.
There is no document specifically for this. But performing segmentation programmatically in Python w/out the Slicer UI is quite easy.

As @lassoan mentioned, you just need this script: https://github.com/lassoan/SlicerMONAIAuto3DSeg/blob/main/MONAIAuto3DSeg/Scripts/auto3dseg_segresnet_inference.py

In a virtual environment with MONAI installed:

pip install monai[fire,pyyaml,nibabel,pynrrd,psutil,tensorboard,skimage,itk,tqdm]

an example command will be:

python auto3dseg_segresnet_inference.py --model_file /PATH_TO_THE_MODEL_PT/model.pt --image_file /PATH_TO_SAMPLE_IMAGE/sample.nrrd --result_file /PATH_TO_OUTPUT/

If your images are in .nii.gz format, you may need to change these lines by this only:

nib.save(nib.Nifti1Image(seg, affine = original_affine), result_file)

Remember to do the import: import nibabel as nib

Hope this helps,

@mattwarkentin
Copy link
Author

Great, thanks for the extra info @diazandr3s. This will definitely get me on the right track.

@diazandr3s
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants