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>255:
l=255
elif l<0:
l=0
imgsharp.putpixel((i,j),l)
imgsharp.show()
그레이 스케일 이미지에 3x3 마스크 크기의 고역 (선명도) 필터를 적용하고 싶습니다. 하지만 오류가 나타납니다. 실수를 수정하고 오류를 수정 한 후 어떻게하면이 코드에서 이미지를 선명하게 할 수 있습니까?python : 이미지 선명하게 적용/오류 적용
오류 :
Traceback (most recent call last):
File "C:\sharp.py", line 16, in <module>
l=pixels[i-k+1,j-m+1]*sharp[i]
IndexError: image index out of range
당신이 이미지의 경계 처리되지 않기 때문에 당신이 언급 한 특정 오류가 당신