title: Error with image sharpening in Python
body: <pre><code>from PIL import Image
  fp="C:\\lena.jpg"
  img=Image.open(fp)
  w,h=img.size
  pixels=img.load()
  
  imgsharp=Image.new(img.mode,img.size,color=0)
  sharp=[0,-1,0,-1,8,-1,0,-1,0]
  
  for i in range(w):
      for j in range(h):
  
          for k in range(3):
                  for m in range(3):
                      l=pixels[i-k+1,j-m+1]*sharp[i]
  
          if l&gt;255:
              l=255
          elif l&lt;0:
              l=0
          imgsharp.putpixel((i,j),l)
  
  imgsharp.show()
  </code></pre>
  
  <p>I want to apply a high pass (sharpening) filter with 3x3 mask size to a grayscale image. But I am getting an error:</p>
  
  <pre><code>Traceback (most recent call last):
  File "C:\sharp.py", line 16, in &lt;module&gt;
  l=pixels[i-k+1,j-m+1]*sharp[i]
  IndexError: image index out of range
  </code></pre>
  
  <p>How can I fix my mistake and how can I get the image sharpening to work in this code?</p>