| 151 | |
| 152 | |
| 153 | def _stack_images(image_list: list, meta_dict: dict, to_cupy: bool = False): |
| 154 | if len(image_list) <= 1: |
| 155 | return image_list[0] |
| 156 | if not is_no_channel(meta_dict.get(MetaKeys.ORIGINAL_CHANNEL_DIM, None)): |
| 157 | channel_dim = int(meta_dict[MetaKeys.ORIGINAL_CHANNEL_DIM]) |
| 158 | if to_cupy and has_cp: |
| 159 | return cp.concatenate(image_list, axis=channel_dim) |
| 160 | return np.concatenate(image_list, axis=channel_dim) |
| 161 | # stack at a new first dim as the channel dim, if `'original_channel_dim'` is unspecified |
| 162 | meta_dict[MetaKeys.ORIGINAL_CHANNEL_DIM] = 0 |
| 163 | if to_cupy and has_cp: |
| 164 | return cp.stack(image_list, axis=0) |
| 165 | return np.stack(image_list, axis=0) |
| 166 | |
| 167 | |
| 168 | @require_pkg(pkg_name="itk") |