Skip to content

Commit

Permalink
FIX: bspline grid func improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
eilidhmacnicol committed Apr 20, 2021
1 parent dcf423c commit 638f459
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions niworkflows/utils/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,14 @@ def _bspline_grid(in_file):
"""Estimate B-Spline fitting distance grid using the number of slices of ``in_file``."""
import nibabel as nb
import numpy as np
import math

img = nb.load(in_file)
slices = img.header.get_data_shape()
# find ratio of slices in each dimension wrt dimension with most slices
ratio = [s / slices[np.argmax(slices)] for s in slices]
# find common factor for the dimensions with the most and least slices
ratio_factor = ratio[np.argmax(ratio)] / ratio[np.argmin(ratio)]
zooms = img.header.get_zooms()[:3]
# find extent of each dimension wrt voxel sizes
extent = (np.array(img.shape[:3]) - 1) * zooms
# convert ratio to integers
mesh_res = [f"{round(i * ratio_factor)}" for i in ratio]
retval = [f"{math.ceil(i / extent[np.argmin(extent)])}" for i in extent]
# return string for command line call
return f"-b [{'x'.join(mesh_res)}]"
return f"-b [{'x'.join(retval)}]"

0 comments on commit 638f459

Please # to comment.