def image(data): """ Creates a NiBabel image for the supplied data. The image object will be of a generic type and only made concrete during the saving process (nibabel.loadsave.save() takes care of this). No special meta-data can be associated with the image. @param data: a numpy array of arbitrary type @return: a NiBabel image for data of generic type SpatialImage """ image = SpatialImage(data, None) image.update_header() return image
def image_new(data, filename): """ Creates a NiBabel image for the supplied data. The function intends to directly create the appropriate image type, depending on the image header. @param data: a numpy array of arbitrary type @param filename the intended filename with the file ending telling the image type @return: a NiBabel image for data of any nibabel image type """ # extract suffix and return apropriate image suffix = filename.split('.')[-1].lower() if not suffix in __suffix_to_type: suffix = '.'.join(map(lambda x: x.lower(), filename.split('.')[-2:])) if not suffix in __suffix_to_type: image = SpatialImage(data, None) image.update_header() return image image = __suffix_to_type[suffix](data, None) image.update_header() return image