Source code for clinicadl.transforms.extraction.image
from__future__importannotationsfromloggingimportgetLoggerfromtypingimportTYPE_CHECKING,Any,TypeVarimporttorchfromclinicadl.utils.configimportObjectConfigfromclinicadl.utils.dictionary.wordsimportSAMPLE_POSITION,SAMPLE_TYPEfrom.baseimportExtraction,ImplementedExtractionifTYPE_CHECKING:fromclinicadl.data.structuresimportDataPointlogger=getLogger(__name__)DataPointT=TypeVar("DataPointT",bound="DataPoint")classImageConfig(ObjectConfig["Image"]):""" Config class for Image extraction. """@classmethoddef_get_class(cls)->type[Image]:"""Returns the class associated to this config class."""returnImage
[docs]classImage(Extraction[ImageConfig]):""" Transform class for full image extraction, which is equivalent to no extraction. Adds the following keys to the input :py:class:`~clinicadl.data.structures.DataPoint`: - ``sample_type`` : ``"image"`` - ``sample_position``: ``None`` Not relevant here. Only for consistency. """_config_type=ImageConfigdef__init__(self):self.config=ImageConfig()@propertydefsample_type(self)->str:""" The type of the sample returned by this extraction, among {"image", "slice", "patch"}. """returnImplementedExtraction.IMAGE.value.lower()def_extract_datapoint_from_position(self,data_point:DataPointT,sample_position:Any)->DataPointT:self._add_info(data_point,sample_position)returndata_pointdef_extract_tensor_sample(self,image_tensor:torch.Tensor,sample_position:int,)->torch.Tensor:""" Returns the entire image tensor as no extraction is performed. """returnimage_tensordef_get_sample_positions(self,data_point:DataPoint)->list[int]:""" Returns the positions of the samples in the image, which is always [0] here. """return[0]def_add_info(self,data_point:DataPoint,sample_position:int)->None:""" Adds relevant info in the datapoint. """data_point[SAMPLE_TYPE]=self.sample_typedata_point[SAMPLE_POSITION]=None