python 3.x - Making functions that randomly pick pixel and read colors -


i trying make function picks pixel point randomly in image , reads color(rgb) of it.

however, entirely stuck it. can give me idea?

i glad helps. thank you.

btw i'm using python 3.4.4.

below got far:

def color_of_pixel(image,win):  y in range(0,image.getheight()):    x in range(0,image.getwidth()):      get_color=getpixel(x,y)      print(get_color) 

  

there many first 1 use default python random library

import random   x,y = image.shape #assume image numpy array or nested list aka plt.imread() = random.randint(0, len(x)) j = random.randint(0, len(y)) return pixel[i][j] 

you can run loop if want generate more 1 random pixel way use numpy random can use similar way did above can generate many random number @ once

https://docs.scipy.org/doc/numpy/reference/generated/numpy.random.randint.html


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -