Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions monailabel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
from distutils.util import strtobool
from importlib.metadata import distributions
from typing import Any, Dict, List, Optional

Expand Down Expand Up @@ -115,6 +116,10 @@ class Settings(BaseSettings):
else "https://huggingface.co/facebook/sam2-hiera-large/resolve/main/sam2_hiera_l.yaml"
)

MONAI_LABEL_USE_ITK_FOR_DICOM_SEG: bool = bool(
strtobool(os.environ.get("MONAI_LABEL_USE_ITK_FOR_DICOM_SEG", "True"))
)

model_config = SettingsConfigDict(
env_file=".env",
case_sensitive=True,
Expand Down
8 changes: 7 additions & 1 deletion monailabel/datastore/utils/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from monai.transforms import LoadImage
from pydicom.filereader import dcmread

from monailabel.config import settings
from monailabel.datastore.utils.colors import GENERIC_ANATOMY_COLORS
from monailabel.transform.writer import write_itk
from monailabel.utils.others.generic import run_command
Expand Down Expand Up @@ -80,7 +81,12 @@ def binary_to_image(reference_image, label, dtype=np.uint8, file_ext=".nii.gz"):
return output_file


def nifti_to_dicom_seg(series_dir, label, label_info, file_ext="*", use_itk=True) -> str:
def nifti_to_dicom_seg(series_dir, label, label_info, file_ext="*", use_itk=None) -> str:

# Only use config if no explicit override
if use_itk is None:
use_itk = settings.MONAI_LABEL_USE_ITK_FOR_DICOM_SEG

start = time.time()

label_np, meta_dict = LoadImage(image_only=False)(label)
Expand Down
2 changes: 1 addition & 1 deletion monailabel/endpoints/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def run_inference(
suffixes = [".nii", ".nii.gz", ".nrrd"]
image_path = [image_uri.replace(suffix, "") for suffix in suffixes if image_uri.endswith(suffix)][0]
res_img = result.get("file") if result.get("file") else result.get("label")
dicom_seg_file = nifti_to_dicom_seg(image_path, res_img, p.get("label_info"), use_itk=True)
dicom_seg_file = nifti_to_dicom_seg(image_path, res_img, p.get("label_info"))
result["dicom_seg"] = dicom_seg_file

return send_response(instance.datastore(), result, output, background_tasks)
Expand Down
Loading