Skip to content

Commit 08229d1

Browse files
committed
Add optional data parameter to from_image, call from_image from image_like
1 parent f44b46e commit 08229d1

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
@@ -847,7 +847,7 @@ def instance_to_filename(klass, img, filename):
847847
img.to_filename(filename)
848848

849849
@classmethod
850-
def from_image(klass, img):
850+
def from_image(klass, img, data=None):
851851
''' Class method to create new instance of own class from `img`
852852
853853
Parameters
@@ -861,7 +861,7 @@ def from_image(klass, img):
861861
cimg : ``spatialimage`` instance
862862
Image, of our own class
863863
'''
864-
return klass(img.dataobj,
864+
return klass(img.dataobj if data is None else data,
865865
img.affine,
866866
klass.header_class.from_header(img.header),
867867
extra=img.extra.copy())
@@ -878,5 +878,4 @@ def image_like(img, data):
878878
''' Create new SpatialImage with metadata of `img`, and data
879879
contained in `data`.
880880
'''
881-
return img.__class__(data, img.affine, img.header.copy(),
882-
extra=img.extra.copy())
881+
return img.from_image(img, data)

0 commit comments

Comments
 (0)