So I have a numpy array which I convert into a list of tuples like this
orig_img = cv2.imread("plane.jpg")
def cvimg_to_list(img: numpy.ndarray) -> list:
img_lst = []
img_row = img.shape[0] # Width
img_column = img.shape[1] # Height
for x in range(0, img_row): # (Width * Height)
for y in range(0, img_column):
img_lst.append((img[x,y][0], #B value
img[x,y][1], #G value
img[x,y][2])) #R value
return img_lst
orig_list = cvlib.cvimg_to_list(orig_img)
print(orig_list) #hundreds of thousands of values
>>> [(139, 80, 48), (135, 82, 39), ...]
Now I want to write a function generator_from_image which takes a image and returns a function which given an index for a pixel returns the color of that pixel.
The functions that are returned should look like the representation for images as one-dimensional lists. The return value for index 0 is the pixel in the upper left corner, the return value for the width of the image is the upper right corner, and so on.
Here's what I tried:
def generator_from_image(img):
def get_color_from_index(x, y):
color = (x, y) #Need help here...
return color
return get_color_from_index(img)