0

I tried to draw a simple 10x10 black image with a single red pixel at the 8,8 coordinate.

This was my attempt:

from PIL import Image
import numpy as np

foo = np.zeros([10,10,3])
foo[8,8] = [255,0,0] # Draw a red pixel
img = Image.fromarray(foo, 'RGB')
img.save('out.png')

Sadly for some reason the entire image stays black (enlarged):

enter image description here

When printing "foo" the [255,0,0] entry is there, so I am confused on what is wrong here.

1 Answer 1

2

You need to specify the data type of the numpy array to int8.

So you would have

foo = np.zeros([10,10,3], dtype=np.int8)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.