import torch


def add_coord_channels(image_tensor: torch.Tensor, device: str = 'cpu') -> torch.Tensor:
    """ Adds channels containing pixel indices (x and y coordinates) to an image. """
    B, C, H, W = image_tensor.shape
    x_grid = torch.linspace(start=-1.0, end=1.0, steps=H).view((1, 1, H, 1)).to(device)
    x_map = torch.tile(x_grid, (B, 1, 1, W)).to(device)
    y_grid = torch.linspace(start=1.0, end=-1.0, steps=W).view((1, 1, 1, W)).to(device)
    y_map = torch.tile(y_grid, (B, 1, H, 1)).to(device)
    return torch.cat([image_tensor, x_map, y_map], dim=1).to(device)