# Transform Image Operator Authors: derekdqc, shiyu22 ## Overview This operator uses PyTorch to transform the image, such as cropping, PIL.Image and Tensor conversion, normalization and other operations on the image. In computer vision (CV) directions, image transformations are usually an indispensable part, which can be used to pre-process images and enhance data. And transforms are common image transformations, they can be chained together using [`Compose`](https://pytorch.org/vision/stable/transforms.html#torchvision.transforms.Compose) in Pytorch. ## Interface `__init__(self, size: int)` **Args:** ​ size(`int`): ​ The size of the output image. `__call__(self, img_tensor: Union[np.ndarray, Image.Image, torch.Tensor, str])` **Args:** ​ img_tensor(`Union[np.ndarray, Image.Image, torch.Tensor, str]`): ​ Original image data, the type can be np.ndarry, PIL.image, or str path of the image. **Returns:** ​ (`Tuple[('img_transformed', torch.Tensor)]`) ​ The tensor of the transformed image. ## How to use ### Requirements You can get the required python package by [requirements.txt](./requirements.txt). - pillow ### How it works The `towhee/transform-image` Operator is used for image transformation and is an important part of data preprocessing. It can be added to the pipeline and is usually used as the first custom operator of the pipeline. For example, it's the first Operator named processing within [image_embedding_resnet50](https://hub.towhee.io/towhee/image-embedding-resnet50) pipeline, and it is the red box in the picture below. ![img](./readme_src/operator.png) ## Reference - https://pytorch.org/vision/stable/transforms.html