Skip to content

Commit facd122

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

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
@@ -442,7 +442,7 @@ def get_affine(self):
442442
return self.affine
443443

444444
@classmethod
445-
def from_image(klass, img):
445+
def from_image(klass, img, data=None):
446446
''' Class method to create new instance of own class from `img`
447447
448448
Parameters
@@ -456,7 +456,7 @@ def from_image(klass, img):
456456
cimg : ``spatialimage`` instance
457457
Image, of our own class
458458
'''
459-
return klass(img.dataobj,
459+
return klass(img.dataobj if data is None else data,
460460
img.affine,
461461
klass.header_class.from_header(img.header),
462462
extra=img.extra.copy())
@@ -520,5 +520,4 @@ def image_like(img, data):
520520
''' Create new SpatialImage with metadata of `img`, and data
521521
contained in `data`.
522522
'''
523-
return img.__class__(data, img.affine, img.header.copy(),
524-
extra=img.extra.copy())
523+
return img.from_image(img, data)

0 commit comments

Comments
 (0)