Skip to content

Commit e2bc86d

Browse files
committed
Add optional data parameter to from_image, call from_image from image_like
1 parent e33149d commit e2bc86d

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

639639
@classmethod
640-
def from_image(klass, img):
640+
def from_image(klass, img, data=None):
641641
''' Class method to create new instance of own class from `img`
642642
643643
Parameters
@@ -651,7 +651,7 @@ def from_image(klass, img):
651651
cimg : ``spatialimage`` instance
652652
Image, of our own class
653653
'''
654-
return klass(img.dataobj,
654+
return klass(img.dataobj if data is None else data,
655655
img.affine,
656656
klass.header_class.from_header(img.header),
657657
extra=img.extra.copy())
@@ -684,5 +684,4 @@ def image_like(img, data):
684684
''' Create new SpatialImage with metadata of `img`, and data
685685
contained in `data`.
686686
'''
687-
return img.__class__(data, img.affine, img.header.copy(),
688-
extra=img.extra.copy())
687+
return img.from_image(img, data)

0 commit comments

Comments
 (0)