python - Find Position of Value in numpy Array -


i trying find position in array called imagearray

from pil import image, imagefilter import numpy np  imagelocation = image.open("images/numbers/0.1.png")  #creates array [3d] of image colours imagearray = np.asarray(imagelocation) arrayrgb = imagearray[:,:,:3] #removes alpha value output  print(arrayrgb) #rgb output  print(round(np.mean(arrayrgb),2)) colourmean = np.mean(arrayrgb) #outputs mean of values rgb in each pixel 

this code searches each point individually in array , if above mean supposed become 255 if less 0. how can find position in array can edit value.

for row in arrayrgb:     pixelrgb in row:         #looks @ each pixel individually         print(pixelrgb)         if(pixelrgb > colourmean):             pixelrgb[positionpixel] = 255         elif(pixelrgb < colourmean):             pixelrgb[positionpixel] = 0 

as example, let's consider array:

>>> import numpy np >>> array([[0, 1, 2],        [3, 4, 5],        [6, 7, 8]]) 

now, let's apply transformation it:

>>> np.where(a>a.mean(), 255, 0) array([[  0,   0,   0],        [  0,   0, 255],        [255, 255, 255]]) 

the general form np.where np.where(condition, x, y). wherever condition true, returns x. wherever condition false, returns y.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -