syna.utils.transforms module

class syna.utils.transforms.CenterCrop(size)[source]

Bases: object

Crop the center region of a PIL Image.

The size may be an int or (width, height). If the requested size is larger than the image, behavior follows PIL.crop (it will include padding from image).

class syna.utils.transforms.Compose(transforms=None)[source]

Bases: object

Compose a sequence of image transforms.

Applies each transform in order to the input image and returns the result. The transforms can accept and return either PIL Images or numpy arrays, depending on the transform implementation.

class syna.utils.transforms.Convert(mode='RGB')[source]

Bases: object

Convert a PIL Image to the requested color mode.

The transform accepts a PIL Image and returns another PIL Image converted to mode. A special-case mode “BGR” converts the image from RGB to BGR by swapping channels (useful for interoperability with frameworks expecting BGR order).

class syna.utils.transforms.ConvertImageDtype(dtype=<class 'numpy.float32'>)[source]

Bases: object

Cast a numpy image array to the specified dtype.

This is a simple dtype conversion utility similar in intent to torchvision.transforms.ConvertImageDtype but implemented for numpy arrays.

class syna.utils.transforms.Flatten[source]

Bases: object

Flatten an array to 1-D.

Returns a flattened view where possible (ravel), suitable for converting image tensors to vectors.

class syna.utils.transforms.Normalize(mean=0, std=1)[source]

Bases: object

Normalize a (C, H, W) numpy array by mean and std.

Mean and std may be scalars or sequences of length C. Broadcasts to match the input array shape and returns a float array with (arr - mean) / std.

class syna.utils.transforms.RandomHorizontalFlip(p=0.5)[source]

Bases: object

Randomly horizontally flip an image with probability p.

Works with both PIL Images and numpy arrays. For numpy arrays this flips along the last horizontal axis and returns a copy to preserve contiguity.

class syna.utils.transforms.Resize(size, interpolation=2)[source]

Bases: object

Resize a PIL Image to the given size.

Size may be an int or a tuple. The pair helper ensures size is (width, height). The interpolation argument accepts PIL resampling filters (default BILINEAR).

syna.utils.transforms.ToFloat

alias of ConvertImageDtype

syna.utils.transforms.ToInt(dtype=<class 'int'>)[source]
class syna.utils.transforms.ToPILImage[source]

Bases: object

Convert a numpy array to a PIL Image.

Accepts arrays in shape (C, H, W), (H, W, C) or (H, W). Float images in [0, 1] will be scaled to [0, 255] and cast to uint8. Other dtypes are converted to uint8.

class syna.utils.transforms.ToTensor[source]

Bases: object

Convert a PIL Image or numpy.ndarray to a float32 numpy array.

Output shape is (C, H, W). For uint8 input the values are scaled to [0.0, 1.0] to match torchvision.transforms.ToTensor. Supports grayscale and RGB images.