Skip to content

Commit 9edb6bd

Browse files
committed
Add optional data parameter to from_image, call from_image from image_like
1 parent db66bb7 commit 9edb6bd

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
@@ -636,7 +636,7 @@ def get_affine(self):
636636
return self.affine
637637

638638
@classmethod
639-
def from_image(klass, img):
639+
def from_image(klass, img, data=None):
640640
''' Class method to create new instance of own class from `img`
641641
642642
Parameters
@@ -650,7 +650,7 @@ def from_image(klass, img):
650650
cimg : ``spatialimage`` instance
651651
Image, of our own class
652652
'''
653-
return klass(img.dataobj,
653+
return klass(img.dataobj if data is None else data,
654654
img.affine,
655655
klass.header_class.from_header(img.header),
656656
extra=img.extra.copy())
@@ -667,5 +667,4 @@ def image_like(img, data):
667667
''' Create new SpatialImage with metadata of `img`, and data
668668
contained in `data`.
669669
'''
670-
return img.__class__(data, img.affine, img.header.copy(),
671-
extra=img.extra.copy())
670+
return img.from_image(img, data)

0 commit comments

Comments
 (0)