pyhealth.processors.ImageProcessor#
Processor for image data.
- class pyhealth.processors.ImageProcessor(image_size=224, to_tensor=True, normalize=False, mean=None, std=None, mode=None)[source]#
Bases:
FeatureProcessorFeature processor for loading images from disk and converting them to tensors.
- Parameters:
image_size (
int) – Desired output image size (will resize to square image). Defaults to 224.to_tensor (
bool) – Whether to convert image to tensor. Defaults to True.normalize (
bool) – Whether to normalize image values to [0, 1]. Defaults to False.mean (
Optional[List[float]]) – Precomputed mean for normalization.std (
Optional[List[float]]) – Precomputed std for normalization.mode (
Optional[str]) – PIL image mode to convert the image to before processing. Common modes: ‘RGB’, ‘RGBA’, ‘L’ (grayscale), ‘P’ (palette). If None, keeps the original mode. Defaults to None.
- Raises:
ValueError – If normalization parameters are inconsistent.
- process(value)[source]#
Process a single image path into a transformed tensor image.
- Parameters:
value (
Union[str,Path]) – Path to image file as string or Path object.- Return type:
- Returns:
Transformed image tensor.
- Raises:
FileNotFoundError – If the image file does not exist.
- is_token()[source]#
Image data is continuous (float-valued pixel intensities), not discrete tokens.
- Return type:
- Returns:
False.
- spatial()[source]#
Spatial axes for the output tensor (C, H, W).
Channels are not spatial; height and width are.
- fit(samples, field)#
Fit the processor to the samples.
- load(path)#
Optional: Load processor state from disk.