Hello
I'm trying to read every pixel of an image and return the RGB data of each pixel into a table using the Python tool.
So far I created this script in Python
from PIL import Image
def rgb_of_pixel(img_path, x, y):
im = Image.open(img_path).convert('RGB')
r,g,b = im.getpixel((x,y))
a = (r,g, b)
return a
img = r"C:\Users\Desktop\stickers-arc-en-ciel.jpg"
print (rgb_of_pixel(img, 5, 5),1)
I'm not familiar with the Python tool so I don't know how to output the data generated.
This code reads and prints in the log the data for one pixel which is nice, but what I need is to read every pixel and return it into a table with 3 columns R/G/B.
First would be to understand how to output the data I generated into an output anchor. Does someone have the answer?
Thanks !
Solved! Go to Solution.
Hey,
For those interested, I managed to get the output I want. I had to add a few lines to my code to make it work. I used the example in Designer to finish it:
from ayx import Alteryx
import pandas as pd
from PIL import Image
def rgb_of_pixel(img_path, x, y):
im = Image.open(img_path).convert('RGB')
r,g,b = im.getpixel((x,y))
a = (r,g, b)
return a
img = r"C:\Users\Desktop\download.png"
table = [
[rgb_of_pixel(img, 5, 5)]
]
dataframe = pd.DataFrame(table)
Alteryx.write(dataframe, 1)