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
(ext_name, *im_writers)
| 65 | |
| 66 | |
| 67 | def register_writer(ext_name, *im_writers): |
| 68 | """ |
| 69 | Register ``ImageWriter``, so that writing a file with filename extension ``ext_name`` |
| 70 | could be resolved to a tuple of potentially appropriate ``ImageWriter``. |
| 71 | The customised writers could be registered by: |
| 72 | |
| 73 | .. code-block:: python |
| 74 | |
| 75 | from monai.data import register_writer |
| 76 | # `MyWriter` must implement `ImageWriter` interface |
| 77 | register_writer("nii", MyWriter) |
| 78 | |
| 79 | Args: |
| 80 | ext_name: the filename extension of the image. |
| 81 | As an indexing key, it will be converted to a lower case string. |
| 82 | im_writers: one or multiple ImageWriter classes with high priority ones first. |
| 83 | """ |
| 84 | fmt = f"{ext_name}".lower() |
| 85 | if fmt.startswith("."): |
| 86 | fmt = fmt[1:] |
| 87 | existing = look_up_option(fmt, SUPPORTED_WRITERS, default=()) |
| 88 | all_writers = im_writers + existing |
| 89 | SUPPORTED_WRITERS[fmt] = all_writers |
| 90 | |
| 91 | |
| 92 | def resolve_writer(ext_name, error_if_not_found=True) -> Sequence: |
searching dependent graphs…