clinicadl.transforms.MergeFields¶
- class clinicadl.transforms.MergeFields(*keys: str, output_key: str, **kwargs)[source]¶
Transform to merge several values of a
DataPoint.The result of the merger depends on the type of values:
torch.Tensorandnumpy.ndarrayare stacked along a new dimension (so they are expected to all have the same shape);torchio.Imageare concatenated along the channel dimension (so they are expected to all have the same spatial shape);listsandtuplesare concatenated;otherwise, the values are just put in a list.
This transform inherits from
torchio.Transform, and therefore any argument accepted by this parent class can be passed via a keyword argument here. Particularly, you may be interested incopyto specify if the outputDataPointshould be the same object as the input or a deepcopy.- Parameters:
*keys (str) – The keys whose values should be merged.
output_key (str) – The name of key in the
DataPointcorresponding to the output of the merger.**kwargs (Any) – Any keyword argument accepted by
torchio.Transform.
Example
from clinicadl.transforms import MergeFields from clinicadl.data.structures.examples import Colin27DataPoint import numpy as np data = Colin27DataPoint(age=55, sex="M", array_1=np.zeros(2), array_2=np.ones(2))
>>> MergeFields("age", "sex", output_key="label")(data)["label"] [55, 'M'] >>> MergeFields("array_1", "array_2", output_key="label")(data)["label"] [[0. 0.] [1. 1.]]
- __call__(data: InputType) InputType¶
Transform data and return a result of the same type.
- Parameters:
data (
TypeVar(InputType, bound=Union[Subject,Image,Tensor,ndarray,Image,dict,Nifti1Image])) – Instance oftorchio.Subject, 4Dtorch.Tensorornumpy.ndarraywith dimensions \((C, W, H, D)\), where \(C\) is the number of channels and \(W, H, D\) are the spatial dimensions. If the input is a tensor, the affine matrix will be set to identity. Other valid input types are a SimpleITK image, atorchio.Image, a NiBabel Nifti1 image or adict. The output type is the same as the input type.