title: Python OpenCV image editing: Faster way to edit pixels
body: <p>Using python (openCV2, tkinter etc) I've created an app (a very amateur one) to change blue pixels to white. The images are high quality jpgs or PNGS. </p>
  
  <p>The process: Search every pixel of an image and if the 'b' value of BGR is higher than x, set pixel to white (255, 255, 255). </p>
  
  <p>The problem: There are about 150 pictures to process at a time, so the above process takes quite long. It's around 9 - 15 seconds per iteration depending on the images size (resizing the image speeds up the process, but not ideal). </p>
  
  <p>Here is the code (with GUI and exception handling elements removed for simplicity): </p>
  
  <pre><code>for filename in listdir(sourcefolder):
          # Read image and set variables 
          frame = imread(sourcefolder+"/"+filename)
          rows = frame.shape[0]
          cols = frame.shape[1]
  
          # Search pixels. If blue, set to white. 
          for i in range(0,rows):
              for j in range(0,cols):
                  if frame.item(i,j,0) &gt; 155:
                      frame.itemset((i,j,0),255)
                      frame.itemset((i,j,1),255)
                      frame.itemset((i,j,2),255)
          imwrite(sourcecopy+"/"+filename, frame)
          #release image from memory 
          del frame     
  </code></pre>
  
  <p>Any help on increasing efficiency / speed would be greatly appreciated!  </p>