Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve map shape and dtype when a map is merged #341

Merged
merged 4 commits into from
Apr 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions siibra/volumes/nifti.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def loader(url):
self._img_loaders = {lbl: loader(url) for lbl, url in src.items()}
else:
raise ValueError(f"Invalid source specification for {self.__class__}: {src}")

if not isinstance(src, nib.Nifti1Image):
self._init_url = src

Expand Down Expand Up @@ -95,9 +94,9 @@ def _merge_fragments(self) -> nib.Nifti1Image:
s0 = np.identity(4)
s0[:3, -1] = list(bbox.minpoint.transform(np.linalg.inv(img.affine)))
result_affine = np.dot(img.affine, s0) # adjust global bounding box offset to get global affine
voxdims = np.dot(np.linalg.inv(result_affine), np.r_[bbox.shape, 1])[:3]
result_arr = np.zeros((voxdims + .5).astype('int'))
result = nib.Nifti1Image(dataobj=result_arr, affine=result_affine)
voxdims = np.r_[bbox.transform(result_affine).shape].astype(img.dataobj.dtype)
AhmetNSimsek marked this conversation as resolved.
Show resolved Hide resolved
result_arr = np.zeros(voxdims, dtype=img.dataobj.dtype)
result = nib.Nifti1Image(dataobj=result_arr, affine=result_affine, dtype=img.dataobj.dtype)
AhmetNSimsek marked this conversation as resolved.
Show resolved Hide resolved

arr = np.asanyarray(img.dataobj)
Xs, Ys, Zs = np.where(arr != 0)
Expand Down