title: Is there any faster way to loop through Image in python
body: <p>program is about removing the gradient background color
  Currently it takes about 20 second for single image of size 420X560 size
  code is</p>
  <pre class="lang-py prettyprint-override"><code>
  from colormath.color_objects import sRGBColor, LabColor
  from colormath.color_conversions import convert_color
  from colormath.color_diff import delta_e_cie2000
  import matplotlib.pyplot as plt  
  from matplotlib.colors import LogNorm 
  import numpy as np
  import os
  import cv2
    
  def backgroundRemovel(url):    
      img = cv2.imread(url)    
      img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
      plt.imshow(img)
      plt.title('original Image')
      plt.show() 
      color=img[0,0]
      firstPixelRGB = sRGBColor(color[0], color[1], color[2], is_upscaled=True);
      firstPixelLab = convert_color(firstPixelRGB, LabColor);
      t=img.shape
      x_dim=t[0]
      y_dim=t[1]
      for i in range(x_dim):
            for j in range(y_dim):
              rgbCurPixel=img[i,j]
              curPixelRGB=sRGBColor(rgbCurPixel[0], rgbCurPixel[1], rgbCurPixel[2], is_upscaled=True);
              curPixelLab=convert_color(curPixelRGB, LabColor);
              delta_e = delta_e_cie2000(firstPixelLab, curPixelLab);
              #print(&quot;difference is &quot;+str(delta_e))
              if delta_e&lt;15: 
                  img[i, j] = (0, 0, 0)
     
      return img  
  
  
  fnmae=&quot;image.jpeg&quot;
  open_cv_image = backgroundRemovel(fname)
  plt.imshow(open_cv_image)
  plt.title('Background Removed Image')
  plt.show() 
  
  </code></pre>
  <p>Input Image:
  <a href="https://i.stack.imgur.com/RpVbK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RpVbK.png" alt="&quot;Input&quot;" /></a>
  Desired:
  <a href="https://i.stack.imgur.com/OBCnr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OBCnr.png" alt="&quot;Output&quot;" /></a></p>
  <p>if there is any better way to remove gradient background of image please do share</p>