import math


def grayVector2rgbImage(gray):
    """ Turns a 1D grayscale vector into an rgb image. Only works for square images """
    img = []
    # get sidelength
    length = math.sqrt(len(gray))

    gray_index = 0
    for row_index in range(0, int(length)):
        img.append([])
        for column_index in range (0, int(length)):
            value = gray[gray_index]
            gray_index += 1
            img[row_index].append([value, value, value])

    return img