import torch


def normalize_image_to_tensor(img):
    """
    Normalizes the given np image array and converts it to a tensor.
    Basically, it maps [0, 255] RGB values to [-1, 1]

    :param img: np image array with shape (H, W, C)
    :return: normed image tensor with shape (1, C, H, W)
    """

    normed_image = torch.Tensor((img / 127.5) - 1)
    normed_image = normed_image.clamp(-1, 1)

    normed_image = normed_image.permute(2, 0, 1)

    return normed_image.unsqueeze(0)