Skip to content

Commit

Permalink
Merge pull request #30 from txusser/fix/wholebody
Browse files Browse the repository at this point in the history
Fix/wholebody
  • Loading branch information
txusser authored Apr 1, 2024
2 parents 3f439ee + b68ed86 commit 5ca9a77
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
8 changes: 8 additions & 0 deletions utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
12 changes: 8 additions & 4 deletions utils/wb_tools.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:]
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions wholebody.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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))

Expand Down

0 comments on commit 5ca9a77

Please sign in to comment.