Skip to content

Conversation

@iv-lop
Copy link
Collaborator

@iv-lop iv-lop commented Jul 4, 2025

(1) was hitting permission error when overwriting ~/../segmentations/converted_dcm.nii.gz
added this to spine.py:

if self.save:
# Save spine segmentation
seg_path = os.path.join(
inference_pipeline.output_dir, "segmentations", "spine.nii.gz"
)
# remove stale file & ensure directory exists
if os.path.exists(seg_path):
os.remove(seg_path)
os.makedirs(os.path.dirname(seg_path), exist_ok=True)
nib.save(segmentation, seg_path)

 # Save converted DICOM volume converted_path = os.path.join( inference_pipeline.output_dir, "segmentations", "converted_dcm.nii.gz" ) if os.path.exists(converted_path): os.remove(converted_path) os.makedirs(os.path.dirname(converted_path), exist_ok=True) nib.save(medical_volume, converted_path) 

(2)
in aaa.py:
In class AortaSegmentation.call
added line: inference_pipeline.dicom_series_path = inference_pipeline.input_path
also added: print("DICOM series path is:", inference_pipeline.input_path) for debug

in inference_pipeline.py:
added: def call(self, inference_pipeline=None, input_path: str = None, **kwargs):
and added:
# pick whether we're writing onto self or the wrapped pipeline
target = inference_pipeline or self

 # 1) stash input_path if provided if input_path is not None: target.input_path = input_path # 2) stash everything else (output_dir, model_dir, etc.) for key, value in kwargs.items(): setattr(target, key, value) 

in process.py:
added: pipeline(input_path=path, output_dir=output_dir, model_dir=model_dir)

(3)
changed C2C AAA-pipeline builder code to:

def AAAPipelineBuilder(path, args):
# build the "crop" pipeline and pull out its step‐classes
crop_pipeline = AxialCropperPipelineBuilder(path, args)
# now concatenate its classes with the AAA steps
classes = crop_pipeline.inference_classes + [
aaa.AortaSegmentation(),
aaa.AortaDiameter(),
aaa.AortaMetricsSaver(),
]
return InferencePipeline(classes)

(4)
made this change in aaa.py:

if os.path.isdir(DICOM_PATH): # classic DICOM‐series folder first_file = sorted(os.listdir(DICOM_PATH))[0] dicom = pydicom.dcmread(os.path.join(DICOM_PATH, first_file)) dicom.PhotometricInterpretation = "YBR_FULL" pixel_conversion = dicom.PixelSpacing print("Pixel conversion:", pixel_conversion) RATIO_PIXEL_TO_MM = pixel_conversion[0] # get slice count from the DICOM metadata SLICE_COUNT = dicom.InstanceNumber print("Slice count from DICOM header:", SLICE_COUNT) else: # NIfTI file → grab spacing from the header nii = nib.load(DICOM_PATH) zooms = nii.header.get_zooms() # e.g. (0.7, 0.7, 1.0) RATIO_PIXEL_TO_MM = float(zooms[0]) # get slice count from the loaded volume SLICE_COUNT = len(ct_img) print("Slice count from NIfTI shape:", SLICE_COUNT) 
@iv-lop iv-lop requested a review from malteekj July 4, 2025 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants