Skip to content

Commit 80012ec

Browse files
committed
Add optional data parameter to from_image, call from_image from image_like
1 parent 6b5994e commit 80012ec

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

nibabel/spatialimages.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ def get_affine(self):
537537
return self.affine
538538

539539
@classmethod
540-
def from_image(klass, img):
540+
def from_image(klass, img, data=None):
541541
''' Class method to create new instance of own class from `img`
542542
543543
Parameters
@@ -551,7 +551,7 @@ def from_image(klass, img):
551551
cimg : ``spatialimage`` instance
552552
Image, of our own class
553553
'''
554-
return klass(img.dataobj,
554+
return klass(img.dataobj if data is None else data,
555555
img.affine,
556556
klass.header_class.from_header(img.header),
557557
extra=img.extra.copy())
@@ -641,5 +641,4 @@ def image_like(img, data):
641641
''' Create new SpatialImage with metadata of `img`, and data
642642
contained in `data`.
643643
'''
644-
return img.__class__(data, img.affine, img.header.copy(),
645-
extra=img.extra.copy())
644+
return img.from_image(img, data)

0 commit comments

Comments
 (0)