Python loop through every pixel of image -


how can make below loop(s) faster? pixel pixel loop, , when run it, string of 2 print statements after loop , if-else block respectively.

for in xrange(0, ncols, 1):     p = img[i, row] #image[column, row]      if withinrange(p): #if pixel color, or within range of colors         pixelcount += 1         #print "count after initial row loop is: ", pixelcount  print 'time after initial row loop ', time.time()  if pixelcount == 0: # in other words, no pixels found in whole row                      #- take average middle row each line of text     in xrange(0, ncols, 1):         img[i, row] = 255  else:     start = row print 'time after start = row loop', time.time() 

does have tips on how might optimise this?

the withinrange() function boolean, looks @ whether color intensity (i'm working grayscale images) between 2 specific values, e.g. if img[x, y] between 242 , 254, true.

i looked @ couple of answers seem similar, not quite this. faster way loop through every pixel of image in python?

i working scikit image, open using opencv. basic operation of checking conditions , manipulating value of pixel intensity.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -