``Compose`` provides the ability to chain a series of callables together in a sequential manner. Each transform in the sequence must take a single argument and return a single value. ``Compose`` can be used in two ways: #. With a series of transforms that accept and return a s
| 139 | |
| 140 | |
| 141 | class Compose(Randomizable, InvertibleTransform, LazyTransform): |
| 142 | """ |
| 143 | ``Compose`` provides the ability to chain a series of callables together in |
| 144 | a sequential manner. Each transform in the sequence must take a single |
| 145 | argument and return a single value. |
| 146 | |
| 147 | ``Compose`` can be used in two ways: |
| 148 | |
| 149 | #. With a series of transforms that accept and return a single |
| 150 | ndarray / tensor / tensor-like parameter. |
| 151 | #. With a series of transforms that accept and return a dictionary that |
| 152 | contains one or more parameters. Such transforms must have pass-through |
| 153 | semantics that unused values in the dictionary must be copied to the return |
| 154 | dictionary. It is required that the dictionary is copied between input |
| 155 | and output of each transform. |
| 156 | |
| 157 | If some transform takes a data item dictionary as input, and returns a |
| 158 | sequence of data items in the transform chain, all following transforms |
| 159 | will be applied to each item of this list if `map_items` is `True` (the |
| 160 | default). If `map_items` is `False`, the returned sequence is passed whole |
| 161 | to the next callable in the chain. |
| 162 | |
| 163 | For example: |
| 164 | |
| 165 | A `Compose([transformA, transformB, transformC], |
| 166 | map_items=True)(data_dict)` could achieve the following patch-based |
| 167 | transformation on the `data_dict` input: |
| 168 | |
| 169 | #. transformA normalizes the intensity of 'img' field in the `data_dict`. |
| 170 | #. transformB crops out image patches from the 'img' and 'seg' of |
| 171 | `data_dict`, and return a list of three patch samples:: |
| 172 | |
| 173 | {'img': 3x100x100 data, 'seg': 1x100x100 data, 'shape': (100, 100)} |
| 174 | applying transformB |
| 175 | ----------> |
| 176 | [{'img': 3x20x20 data, 'seg': 1x20x20 data, 'shape': (20, 20)}, |
| 177 | {'img': 3x20x20 data, 'seg': 1x20x20 data, 'shape': (20, 20)}, |
| 178 | {'img': 3x20x20 data, 'seg': 1x20x20 data, 'shape': (20, 20)},] |
| 179 | |
| 180 | #. transformC then randomly rotates or flips 'img' and 'seg' of |
| 181 | each dictionary item in the list returned by transformB. |
| 182 | |
| 183 | The composed transforms will be set the same global random seed if user called |
| 184 | `set_determinism()`. |
| 185 | |
| 186 | When using the pass-through dictionary operation, you can make use of |
| 187 | :class:`monai.transforms.adaptors.adaptor` to wrap transforms that don't conform |
| 188 | to the requirements. This approach allows you to use transforms from |
| 189 | otherwise incompatible libraries with minimal additional work. |
| 190 | |
| 191 | Note: |
| 192 | |
| 193 | In many cases, Compose is not the best way to create pre-processing |
| 194 | pipelines. Pre-processing is often not a strictly sequential series of |
| 195 | operations, and much of the complexity arises when a not-sequential |
| 196 | set of functions must be called as if it were a sequence. |
| 197 | |
| 198 | Example: images and labels |
no outgoing calls
searching dependent graphs…