how do i create an image using a matrix with pycharm and python?

Submitted 3 years, 7 months ago
Ticket #131
Views 269
Language/Framework Python
Priority Medium
Status Closed

I'm trying to create some pixelart using a matrix in pycharm, the problem is that i have never used this program, its supposed to work just by simply selecting if you're working with the RGB model but it doesn't.

import numpy as np
from matplotlib import pyplot as plt
pixels = ([0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0])
    ([0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0])
([0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0])
([0,1,1,0,1,1,0,0,0,0,1,1,0,1,1,0])
print (pixels[2][4])
cv2.waitKey() `

Submitted on Sep 10, 20
add a comment

1 Answer

Verified

You need to save pixels as a numpy array with type uint8 and then let cv2 display it. If you pass 0 to waitKey the window will stay open until you close it manually.

import cv2
import numpy as np

pixels = np.array([[0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0],[0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0],[0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0],[0,1,1,0,1,1,0,0,0,0,1,1,0,1,1,0]], np.uint8)

cv2.imshow("My Image", pixels)
cv2.waitKey(0)

Submitted 3 years, 6 months ago


Latest Blogs