The result looks like this. The result of displaying the edges is much better.
#! /usr/bin/python
from PIL import Image
from numpy import matrix
import matplotlib.pyplot as plt
import sys
import os
import shutil
outfile = os.path.splitext(sys.argv[1])[0] + 'Rank.jpg'
shutil.copy(sys.argv[1], outfile)
img = Image.open(sys.argv[1])
pix = img.load()
width = img.size[0]
height = img.size[1]
width -= 1
height -= 1
out = Image.open(outfile)
outpix = out.load()
# loop thru image
for x in range(1,width,1):
for y in range(1,height,1):
# do calculation
pixellist = []
for mx in range(-1,2,1):
for my in range(-1,2,1):
if mx!=0 and my!=0:
pixellist.append(pix[x+mx,y+my])
pixellist.sort()
val = pixellist[len(pixellist)-1]-pixellist[0]
if val > 255:
val = 255
if val < 0:
val = 0
outpix[x,y] = val
out.show()
out.save(outfile, 'JPEG')
No comments:
Post a Comment