<jupyter_start><jupyter_text>Local path color map will be saved to<jupyter_code>path = 'D:\Code\Web Projects\cat game\Catatonia\dist\sprites'<jupyter_output><empty_output><jupyter_text>Load input image<jupyter_code>palette = cv2.imread('cat_palette_input.png')
print(palette[0][0]) # color is in BGR format cuz OpenCV is very special and different<jupyter_output>[ 82 162 255]<jupyter_text>Write to color map<jupyter_code>def saveColorMap(row):
    color_map = np.ones((512,512,3), np.uint8)
    color_map = np.multiply(color_map, 255)

    # iterate through each pixel collumn of the palette image
    for  i in range(0, palette.shape[1]) :
        
        # get the default pixel color from the top row of the palette image
        default_r = palette[0][i][2]
        default_g = palette[0][i][1]
        default_b = palette[0][i][0]

        # calculate map position & assign to color map
        diag_offset = math.ceil(default_b / 2.0)

        x = default_r + diag_offset
        y = default_g + diag_offset

        # assign color to be mapped to the caluclated position
        color_map[y][x] = palette[row][i]

    # output the image to check in a window
    # cv2.imshow('test', color_map)
    # cv2.waitKey(0)
    # cv2.destroyAllWindows()
        
    fileName = 'color_map_' + str(row) + '.png'
    
    cv2.imwrite(os.path.join(path ,fileName), color_map)
saveColorMap(1)
saveColorMap(2)
saveColorMap(3)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup