def load_medical_data(f):
        """
        load data of different format into numpy array, return data is in xyz

        f: the complete path to the file that you want to load

        """
        filename = osp.basename(f).lower()
        images = []

        # validate nii.gz on lung and mri with correct spacing_resample
        if filename.endswith((".nii", ".nii.gz", ".dcm")):
            itkimage = sitk.ReadImage(f)
            if itkimage.GetDimension() == 4:
                slicer = sitk.ExtractImageFilter()
                s = list(itkimage.GetSize())
                s[-1] = 0
                slicer.SetSize(s)
                for slice_idx in range(itkimage.GetSize()[-1]):
                    slicer.SetIndex([0, 0, 0, slice_idx])
                    sitk_volume = slicer.Execute(itkimage)
                    images.append(sitk_volume)
                images = [sitk.DICOMOrient(img, 'LPS') for img in images]
                f_nps = [sitk.GetArrayFromImage(img) for img in images]
            else:
                f_nps = [nib.load(f).get_fdata(dtype=np.float32)]

        elif filename.endswith(
            (".mha", ".mhd", "nrrd"
             )):  # validate mhd on lung and mri with correct spacing_resample
            itkimage = sitk.DICOMOrient(sitk.ReadImage(f), 'LPS')
            f_np = sitk.GetArrayFromImage(itkimage)
            if f_np.ndim == 4:
                f_nps = [f_np[:, :, :, idx] for idx in range(f_np.shape[3])]
            else:
                f_nps = [f_np]
            f_nps = [np.transpose(f_np, [1, 2, 0]) for f_np in f_nps]
        elif filename.endswith(".raw"):
            raise RuntimeError(
                f"Received {f}. Please only provide path to .mhd file, not to .raw file"
            )

        else:
            raise NotImplementedError

        return f_nps

        load data of different format into numpy array, return data is in xyz

        f: the complete path to the file that you want to load

        
contrib/MedicalSeg/tools/prepare.py