1

I have a http endpoint that wants me to send images in this format:

url = 'https://example_image_url.jpg'
img_bytes = requests.get(url).content
endpoint.predict(img_bytes)

If I have an image in the format of a numpy array, how can I convert it to be identical to the above img_bytes format?

Austin
  • 6,921
  • 12
  • 73
  • 138

2 Answers2

0

Basically, you want to convert pixel values in a numpy array to an image. It seems that Image class in the PIL module as described here should do the trick. Since you haven't specified the values or the size of your numpy array, I cannot suggest whether to use RGB, Grayscale or some other conversion.

Abhineet Gupta
  • 624
  • 4
  • 12
0

It was easier than I expected, just needed .tobytes()

Austin
  • 6,921
  • 12
  • 73
  • 138