MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / _copy_compatible_dict

Function _copy_compatible_dict

monai/data/image_reader.py:130–150  ·  view source on GitHub ↗
(from_dict: dict, to_dict: dict)

Source from the content-addressed store, hash-verified

128
129
130def _copy_compatible_dict(from_dict: dict, to_dict: dict):
131 if not isinstance(to_dict, dict):
132 raise ValueError(f"to_dict must be a Dict, got {type(to_dict)}.")
133 if not to_dict:
134 for key in from_dict:
135 datum = from_dict[key]
136 if isinstance(datum, np.ndarray) and np_str_obj_array_pattern.search(datum.dtype.str) is not None:
137 continue
138 to_dict[key] = str(TraceKeys.NONE) if datum is None else datum # NoneType to string for default_collate
139 else:
140 affine_key, shape_key = MetaKeys.AFFINE, MetaKeys.SPATIAL_SHAPE
141 if affine_key in from_dict and not np.allclose(from_dict[affine_key], to_dict[affine_key]):
142 raise RuntimeError(
143 "affine matrix of all images should be the same for channel-wise concatenation. "
144 f"Got {from_dict[affine_key]} and {to_dict[affine_key]}."
145 )
146 if shape_key in from_dict and not np.allclose(from_dict[shape_key], to_dict[shape_key]):
147 raise RuntimeError(
148 "spatial_shape of all images should be the same for channel-wise concatenation. "
149 f"Got {from_dict[shape_key]} and {to_dict[shape_key]}."
150 )
151
152
153def _stack_images(image_list: list, meta_dict: dict, to_cupy: bool = False):

Callers 6

get_dataMethod · 0.85
get_dataMethod · 0.85
get_dataMethod · 0.85
get_dataMethod · 0.85
get_dataMethod · 0.85
get_dataMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…