title: Apply mask to image with OpenCv Python
body: <p>i'm trying to use opencv with python and I have this problem:</p>
  
  <p>I have an image and a binary mask (single channel image with 0s and 255)
  I want to iterate each pixel of the mask and perform some operations on the original image based on the value of the masks pixel.
  How can I use the numpy optimization to do that? </p>
  
  <p>For example, suppose I want to create a new image where each pixel remains the same if its value in the mask is 0, or its set to (0,0,255) if the pixel in the mask is 255, like:</p>
  
  <pre><code>def inpaint(originalImage, mask):
      [rows, columns, channels] = originalImage.shape
      result = np.zeros((rows,columns,channels))
      for row in range(rows):
          for column in range(columns):
              if(mask[row,column]==0):
                  result[row,column] = originalImage[row,column]
              else:
                  result[row,column] = (0,0,255)
      return result
  </code></pre>
  
  <p>How can I optimize this using numpy?
  Thank you very much</p>