def tile(self, image: torch.Tensor, use_random_tiling: bool = False) -> torch.Tensor:
        """Tile input image into patches.

        Args:
            image: Input image tensor
            use_random_tiling: If ``True``, randomly crop tiles.
                If ``False``, tile in regular grid.

        Returns:
            torch.Tensor: Generated tiles

        Examples:
            >>> tiler = Tiler(tile_size=512, stride=256)
            >>> image = torch.rand(2, 3, 1024, 1024)
            >>> tiles = tiler.tile(image)
            >>> tiles.shape
            torch.Size([18, 3, 512, 512])

        Raises:
            ValueError: If tile size exceeds image size
        """
        if image.dim() == 3:
            image = image.unsqueeze(0)

        self.batch_size, self.num_channels, self.input_h, self.input_w = image.shape

        if self.input_h < self.tile_size_h or self.input_w < self.tile_size_w:
            msg = f"Tile size {self.tile_size_h, self.tile_size_w} exceeds image size {self.input_h, self.input_w}"
            raise ValueError(msg)

        self.resized_h, self.resized_w = compute_new_image_size(
            image_size=(self.input_h, self.input_w),
            tile_size=(self.tile_size_h, self.tile_size_w),
            stride=(self.stride_h, self.stride_w),
        )

        image = upscale_image(image, size=(self.resized_h, self.resized_w), mode=self.mode)

        return self.__random_tile(image) if use_random_tiling else self.__unfold(image)
Tile input image into patches.

        Args:
            image: Input image tensor
            use_random_tiling: If ``True``, randomly crop tiles.
                If ``False``, tile in regular grid.

        Returns:
            torch.Tensor: Generated tiles

        Examples:
            >>> tiler = Tiler(tile_size=512, stride=256)
            >>> image = torch.rand(2, 3, 1024, 1024)
            >>> tiles = tiler.tile(image)
            >>> tiles.shape
            torch.Size([18, 3, 512, 512])

        Raises:
            ValueError: If tile size exceeds image size
        
src/anomalib/data/utils/tiler.py