From b135238a8636464e273b51787bb8eaa3ad9d787e Mon Sep 17 00:00:00 2001 From: YerePhy Date: Tue, 26 Mar 2024 15:10:57 +0100 Subject: [PATCH 1/3] Adding a missing function for 4D data. --- utils/tools.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/utils/tools.py b/utils/tools.py index df4173c..6f411d0 100644 --- a/utils/tools.py +++ b/utils/tools.py @@ -1001,3 +1001,11 @@ def change_format(image_hdr, newFormat, logfile): hdr.set_data_shape(data.shape) imageToWrite = nib.AnalyzeImage(data, img.affine, hdr) nib.save(imageToWrite, image_hdr) + +def fix_4d_data(data): + shape = data.shape + + if len(shape) == 3: + return data + else: + return data[:, :, :, 0] From 2f2e43d3a41b273a3f1bb6df4fd055b603bd47fe Mon Sep 17 00:00:00 2001 From: YerePhy Date: Tue, 26 Mar 2024 15:13:24 +0100 Subject: [PATCH 2/3] Fixing how voxel sizes are read, using abs value because sometimes the values are negative when reading them from affine matrix. --- utils/wb_tools.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/utils/wb_tools.py b/utils/wb_tools.py index 49bcd22..03382f6 100644 --- a/utils/wb_tools.py +++ b/utils/wb_tools.py @@ -1,8 +1,12 @@ +import sys from os.path import join, dirname import nibabel as nib import numpy as np from scipy.ndimage import gaussian_filter from scipy.ndimage import median_filter +from pyprojroot import here + +sys.path.append(str(here())) from utils import resources as rsc from utils import spm_tools as spm from utils import tools @@ -222,14 +226,14 @@ def join_beds_wb(recons_beds, joint_beds): bed_0_data = bed_0_data[:, :, :-slices_to_remove] - for i in range(1, len(recons_beds) - 1): - print(i) + for i in range(1, len(recons_beds)): + print(f"Bed: {i}") bed = nib.load(recons_beds[i]) bed_data = tools.fix_4d_data(bed.get_fdata()) bed_data = bed_data[:, :, slices_to_remove:-slices_to_remove] bed_0_data = np.append(bed_0_data, bed_data, axis=2) - print(len(recons_beds) - 1) + bed_last = nib.load(recons_beds[len(recons_beds) - 1]) bed_data = tools.fix_4d_data(bed_last.get_fdata()) bed_data = bed_data[:, :, slices_to_remove:] @@ -243,7 +247,7 @@ def join_beds_wb(recons_beds, joint_beds): hdr1.set_data_dtype(dtype) hdr1.set_data_shape(bed_0_data.shape) affine = bed_0.get_affine() - hdr1.set_zooms((affine[0, 0], affine[1, 1], affine[2, 2])) + hdr1.set_zooms((abs(affine[0, 0]), abs(affine[1, 1]), abs(affine[2, 2]))) analyze_img = nib.AnalyzeImage(bed_0_data, hdr1.get_base_affine(), hdr1) nib.save(analyze_img, joint_beds) From b68ed86c85b579658b23c694c4af41450cd2e6b9 Mon Sep 17 00:00:00 2001 From: YerePhy Date: Tue, 26 Mar 2024 15:13:56 +0100 Subject: [PATCH 3/3] Fixing beds dirs and scanner model. --- wholebody.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/wholebody.py b/wholebody.py index 377ac0a..2c09902 100644 --- a/wholebody.py +++ b/wholebody.py @@ -28,7 +28,8 @@ def __init__(self, cfg: DictConfig): self.params = self.cfg["params"] self.config = {k: v for k, v in self.cfg.items() if k != "params"} self.scanner = self.cfg["params"]["scanner"] - self.scanner_model = self.params.get("scanner") + self.scanner_model = str(self.params["scanner"]["scanner_name"]).lower().replace(" ", "_") + self.cfg_omega.params.scanner.scanner_name = self.scanner_model # The following lines will read the general, scanner and config parameters self.sim_type = self.params.get("sim_type") @@ -82,8 +83,8 @@ def run(self): if not exists(bed_dir): os.makedirs(bed_dir) - self.params['center_slice'] = cs - self.params['output_dir'] = output_name + "/Bed_cs_%s" % cs + self.cfg_omega.params.center_slice = int(cs) + self.cfg_omega.params.output_dir = output_name + "/Bed_cs_%s" % cs print("Simulating bed %s with center slice %s" % (j, cs))