PixFix!

PixFix!

Ste kupili nov fotoaparat? Vam deluje? Ne? Ima en vroč pixel? Kje pa je ta pixel? 2058×1469? Točno tam? In se razleze na štiri sosednje piksle? Brez panike! Uporabite PixFix! Popravil vam bo pixel na 2058×1469, ter njegove štiri sosede!

Veselite se!

PS: Za prepisane in narobe popravljene slike ne odgovarjam. Jokajte drugje! 😉


[python]
#!/usr/bin/env python

############################################################################
# Copyright (C) 2008 by David Klasinc
# bigwhale@lubica.net
#
# This program is free software; you can redistribute it and#or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 59 Temple Place – Suite 330, Boston, MA 02111-1307, USA.
############################################################################

import os
import sys
import time
import Image
import shutil
import pyexiv2

from stat import *

def avgPixel (pix1, pix2, pix3, pix4 = None):
if pix4 == None:
avg = ( (pix1[0] + pix2[0] + pix3[0]) / 3,
(pix1[1] + pix2[1] + pix3[1]) / 3,
(pix1[2] + pix2[2] + pix3[2]) / 3
)
else:
avg = ( (pix1[0] + pix2[0] + pix3[0] + pix4[0]) / 4,
(pix1[1] + pix2[1] + pix3[1] + pix4[1]) / 4,
(pix1[2] + pix2[2] + pix3[2] + pix4[2]) / 4
)
return avg

def fixPixel (inFileName):

if not os.path.exists (inFileName):
print “Error: file not found:”, inFileName
sysv.exit ()
inImg = Image.open (inFileName)
inMeta = pyexiv2.Image (inFileName)
inMeta.readMetadata()
tmpTime = inMeta[‘Exif.Image.DateTime’]
unixTime = time.mktime (tmpTime.timetuple())

#
# Averaging pixel at 2058×1468
#
pix1 = inImg.getpixel ((2058, 1467))
pix2 = inImg.getpixel ((2057, 1468))
pix3 = inImg.getpixel ((2059, 1468))

avg = avgPixel (pix1, pix2, pix3)
inImg.putpixel ((2058,1468), avg)

#
# Averaging pixel at 2057×1469
#
pix1 = inImg.getpixel ((2056, 1469))
pix2 = inImg.getpixel ((2057, 1468))
pix3 = inImg.getpixel ((2057, 1470))

avg = avgPixel (pix1, pix2, pix3)
inImg.putpixel ((2057,1469), avg)

#
# Averaging pixel at 2058×1470
#
pix1 = inImg.getpixel ((2057, 1470))
pix2 = inImg.getpixel ((2058, 1471))
pix3 = inImg.getpixel ((2059, 1470))

avg = avgPixel (pix1, pix2, pix3)
inImg.putpixel ((2058,1470), avg)

#
# Averaging pixel at 2059×1469
#
pix1 = inImg.getpixel ((2059, 1468))
pix2 = inImg.getpixel ((2060, 1469))
pix3 = inImg.getpixel ((2059, 1470))

avg = avgPixel (pix1, pix2, pix3)
inImg.putpixel ((2059,1469), avg)

#
# Averaging final pixel at 2058×1469
#
pix1 = inImg.getpixel ((2058, 1468))
pix2 = inImg.getpixel ((2057, 1469))
pix3 = inImg.getpixel ((2058, 1470))
pix4 = inImg.getpixel ((2059, 1469))

avg = avgPixel (pix1, pix2, pix3, pix4)
inImg.putpixel ((2058,1469), avg)

#
# Save it and copy meta data!
#
inImg.save (inFileName, “JPEG”, quality = 99)
inMeta.writeMetadata()

#
# Preserve timestamp from EXIF!
#
os.utime(inFileName, (unixTime, unixTime))

if __name__ == ‘__main__’:

try:
inFileName = sys.argv[1]
except:
print “Usage: pixfix \n”
sys.exit ()

fixPixel (inFileName)

print “Done.”
[/python]

6 thoughts on “PixFix!

  1. Hm, tale je nesramno grde bele barve, tako kot njegovi sosedje. In se stvar opazi pri 1:1 velikosti na monitorju… Na papirju se verjetno res ne bo opazil. Zato sem naredil dva programa, da ne popravljam pixlov na cisto vseh slikah, ki jih potegnem iz aparata ampak samo na tistih, kjer so res opazni. 🙂

Comments are closed.

Comments are closed.