Skip to content

Commit 3ec0328

Browse files
committed
Add optional data parameter to from_image, call from_image from image_like
1 parent 4cf79f6 commit 3ec0328

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
@@ -854,7 +854,7 @@ def instance_to_filename(klass, img, filename):
854854
img.to_filename(filename)
855855

856856
@classmethod
857-
def from_image(klass, img):
857+
def from_image(klass, img, data=None):
858858
''' Class method to create new instance of own class from `img`
859859
860860
Parameters
@@ -868,7 +868,7 @@ def from_image(klass, img):
868868
cimg : ``spatialimage`` instance
869869
Image, of our own class
870870
'''
871-
return klass(img.dataobj,
871+
return klass(img.dataobj if data is None else data,
872872
img.affine,
873873
klass.header_class.from_header(img.header),
874874
extra=img.extra.copy())
@@ -984,5 +984,4 @@ def image_like(img, data):
984984
''' Create new SpatialImage with metadata of `img`, and data
985985
contained in `data`.
986986
'''
987-
return img.__class__(data, img.affine, img.header.copy(),
988-
extra=img.extra.copy())
987+
return img.from_image(img, data)

0 commit comments

Comments
 (0)