Skip to content

Commit

Permalink
refactor module
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul Soni committed Feb 1, 2024
1 parent ed89c51 commit 470ce2b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 183 deletions.
12 changes: 5 additions & 7 deletions models/bamf_nnunet_mr_liver/config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,20 @@ modules:
import_dir: sorted_data
sort_data: true
meta:
mod: 'mr'
mod: '%Modality'

NiftiConverter:
in_datas: dicom:mod=mr
engine: dcm2niix
engine: plastimatch

NNUnetRunner:
in_data: nifti:mod=mr
nnunet_task: 'Task822_Liver_AMD'
nnunet_model: '3d_fullres'
nnunet_task: Task822_Liver_AMD
nnunet_model: 3d_fullres
roi: LIVER

BamfProcessorRunner:

DsegConverter:
source_segs: 'nifti:mod=seg'
source_segs: nifti:mod=seg
target_dicom: dicom:mod=mr
model_name: 'Bamf NNUnet MR Liver'
skip_empty_slices: True
Expand Down
73 changes: 0 additions & 73 deletions models/bamf_nnunet_mr_liver/scripts/BamfProcessor.py

This file was deleted.

56 changes: 0 additions & 56 deletions models/bamf_nnunet_mr_liver/scripts/run.py

This file was deleted.

37 changes: 0 additions & 37 deletions models/bamf_nnunet_mr_liver/scripts/slicer_run.py

This file was deleted.

20 changes: 10 additions & 10 deletions models/bamf_nnunet_mr_liver/utils/BamfProcessorRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
-------------------------------------------------
"""

from mhubio.core import Instance, InstanceData, DataType, FileType, CT, SEG
from mhubio.core import Instance, InstanceData
from mhubio.core import Module, IO
import os, numpy as np
import numpy as np
import SimpleITK as sitk
from skimage import measure, filters
from skimage import measure
import numpy as np
import shutil



Expand All @@ -24,21 +23,22 @@ class BamfProcessorRunner(Module):
@IO.Input('in_data', 'nifti:mod=ct|mr', the='input data to run nnunet on')
@IO.Output('out_data', 'bamf_processed.nrrd', 'nrrd:mod=seg:processor=bamf', data='in_data', the="keep the two largest connected components of the segmentation and remove all other ones")
def task(self, instance: Instance, in_data: InstanceData, out_data: InstanceData) -> None:
# Log bamf runner info
self.v("Running BamfProcessor on....")
self.v(f" > input data: {in_data.abspath}")
self.v(f" > output data: {out_data.abspath}")

# Log bamf runner info
self.log("Running BamfProcessor on....")
self.log(f" > input data: {in_data.abspath}")
self.log(f" > output data: {out_data.abspath}")

# read image
self.v(f"Reading image from {in_data.abspath}")
self.log(f"Reading image from {in_data.abspath}")
img_itk = sitk.ReadImage(in_data.abspath)
img_np = sitk.GetArrayFromImage(img_itk)

# apply post-processing
img_bamf_processed = self.n_connected(img_np)

# store image temporarily
self.v(f"Writing tmp image to {out_data.abspath}")
self.log(f"Writing tmp image to {out_data.abspath}")
img_bamf_processed_itk = sitk.GetImageFromArray(img_bamf_processed)
img_bamf_processed_itk.CopyInformation(img_itk)
sitk.WriteImage(img_bamf_processed_itk, out_data.abspath)
Expand Down

0 comments on commit 470ce2b

Please sign in to comment.