-1

I am trying to convert the numpy array consisting of pixel values of a image to display the image.

Code:

for j in range(hieght):
    for k in range(width):
        y=np.asarray(x[j,k]-10)    
        img=np.array(y)
cv2.imshow('image',img)

It is not able display image

Alicia
  • 1,152
  • 1
  • 23
  • 41
  • 1
    Possible duplicate of [How do I convert a numpy array to (and display) an image?](https://stackoverflow.com/questions/2659312/how-do-i-convert-a-numpy-array-to-and-display-an-image) – Patrick Artner Jan 21 '19 at 16:48

1 Answers1

1

See How do I convert a numpy array to (and display) an image?

from PIL import Image
import numpy as np

w, h = 512, 512
data = np.zeros((h, w, 3), dtype=np.uint8)
data[256, 256] = [255, 0, 0]
img = Image.fromarray(data, 'RGB')
img.save('my.png')
img.show()
RichieK
  • 474
  • 6
  • 15