Uses Numpy to create an array of zeros that matches the size of our image (423 by 253).
with open(‘pic_dict.csv’, newline=”) as csvfile:
reader = csv.DictReader(csvfile)
Opens the CSV.
for row in reader:
x = row[‘a’]
x = int(x)
y = row[‘b’]
y = int(y)
bgr = row[‘c’]
#gets the BGR value out of the 
bgr_edit = str(bgr)
head,sep,tail = bgr_edit.partition(‘ ‘)
b = head.strip(‘[‘)
bgr_tail = tail.strip()
bgr_tail = bgr_tail.replace(“]”,””)
head,sep,tail = bgr_tail.partition(” “)
g = head
r = tail
b = int(b)
g = int(g)
r = int(r)
Reads through each row of the CSV and maps the BGR values to the appropriate pixel location (x,y).
Shows the image with the title (xkcd 1696)
I have created a video (hosted on YouTube) of the program in action. The video shows the CSV created from my previous blog post and the function in action reading the CSV to recreate the image of https://xkcd.com/1696/.
Please note: The function took around 7 minutes to run. I have sped this up for the video on YouTube.