o # i@sUddlmZddlmZmZddlmZmZmZddl Z ddl m Z ddl mZmZmZddlmZddlmZmZmZmZmZdd lmZmZdd lmZmZdd lm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+d Z,d Z-e e.e,dZ/erddl0Z0ddl1Z2ddl3m4Z5ne*ddd\Z0Z6e*d\Z2Z6e*d\Z5Z6gdZ7iZ8de9d<ddZ:d*d+ddZ;GdddZe+d%d Gd&d'd'e<Z?d(d)Z@dS),) annotations)MappingSequence) TYPE_CHECKINGAnycastN) get_logger) DtypeLikeNdarrayOrTensorPathLike) MetaTensor)affine_to_spacing ensure_tupleensure_tuple_reporientation_ras_lps to_affine_nd)ResizeSpatialResample)ascontiguousarraymoveaxis) GridSampleModeGridSamplePadModeInterpolateModeMetaKeysOptionalImportError SpaceKeysconvert_data_typeconvert_to_tensorget_equivalent_dtypelook_up_optionoptional_import require_pkgz?%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s*) module_namefmt)ImageitkT)allow_namespace_pkgnibabelz PIL.Image) ImageWriter ITKWriter NibabelWriter PILWriterSUPPORTED_WRITERSregister_writerresolve_writerloggerdictr-cGsB|}|dr|dd}t|tdd}||}|t|<dS)av Register ``ImageWriter``, so that writing a file with filename extension ``ext_name`` could be resolved to a tuple of potentially appropriate ``ImageWriter``. The customised writers could be registered by: .. code-block:: python from monai.data import register_writer # `MyWriter` must implement `ImageWriter` interface register_writer("nii", MyWriter) Args: ext_name: the filename extension of the image. As an indexing key, it will be converted to a lower case string. im_writers: one or multiple ImageWriter classes with high priority ones first. .Ndefault)lower startswithrr-)ext_nameZ im_writersr$existing all_writersr4r4Y/home/dell461/cl/sdc2/last_ska_mid/HISourceFinder-master-l/src/monai/data/image_writer.pyr.Cs    r.returnrc Cstst|}|dr|dd}g}ttd}t|t|dD]"}z |||Wq$ty9Yq$t yF||Yq$w|sS|rStd|dt |}|t|<|S)a Resolves to a tuple of available ``ImageWriter`` in ``SUPPORTED_WRITERS`` according to the filename extension key ``ext_name``. Args: ext_name: the filename extension of the image. As an indexing key it will be converted to a lower case string. error_if_not_found: whether to raise an error if no suitable image writer is found. if True , raise an ``OptionalImportError``, otherwise return an empty tuple. Default is ``True``. r2r3Nr4r5z!No ImageWriter backend found for ) r-initr7r8get EXT_WILDCARDrappendr Exceptionr)r9Zerror_if_not_foundr$Z avail_writersZdefault_writers_writerZ writer_tupler4r4r<r/\s*       r/c@seZdZdZddZddZd4dd Zd5d6ddZed7ddZ eddde j e j dejfd8d$d%Ze & ' d9d:d/d0Zed;das   r>r)r=r)A __future__rcollections.abcrrtypingrrrnumpyr`monai.apps.utilsr monai.configr r r monai.data.meta_tensorr monai.data.utilsr rrrrZmonai.transforms.spatial.arrayrr0monai.transforms.utils_pytorch_numpy_unificationrr monai.utilsrrrrrrrrrrr r! DEFAULT_FMTr@rQr0r&r(rrr%rrw__all__r-rr.r/r)r*r+r,r>r4r4r4r<sJ   8     !^;  ?