torch_geometric.transforms.ToSLIC

class ToSLIC(add_seg: bool = False, add_img: bool = False, **kwargs: Any)[source]

Bases: BaseTransform

Converts an image to a superpixel representation using the skimage.segmentation.slic() algorithm, resulting in a torch_geometric.data.Data object holding the centroids of superpixels in data.pos and their mean color in data.x (functional name: to_slic).

This transform can be used with any torchvision dataset.

from torchvision.datasets import MNIST
import torchvision.transforms as T
from torch_geometric.transforms import ToSLIC

transform = T.Compose([T.ToTensor(), ToSLIC(n_segments=75)])
dataset = MNIST('/tmp/MNIST', download=True, transform=transform)
Parameters:
  • add_seg (bool, optional) – If set to True, will add the segmentation result to the data object. (default: False)

  • add_img (bool, optional) – If set to True, will add the input image to the data object. (default: False)

  • **kwargs (optional) – Arguments to adjust the output of the SLIC algorithm. See the SLIC documentation for an overview.