{"id":1446,"date":"2008-07-09T00:25:57","date_gmt":"2008-07-08T22:25:57","guid":{"rendered":"http:\/\/www.lubica.net\/bigwhale\/blog\/?p=1446"},"modified":"2008-07-09T00:27:41","modified_gmt":"2008-07-08T22:27:41","slug":"pixfix","status":"publish","type":"post","link":"https:\/\/lubica.net\/bigwhale\/blog\/pixfix\/","title":{"rendered":"PixFix!"},"content":{"rendered":"<p>Ste kupili nov fotoaparat? Vam deluje? Ne? Ima en vro\u010d pixel? Kje pa je ta pixel? 2058&#215;1469? To\u010dno tam? In se razleze na \u0161tiri sosednje piksle? Brez panike! Uporabite PixFix! Popravil vam bo pixel na 2058&#215;1469, ter njegove \u0161tiri sosede!<\/p>\n<p>Veselite se!<\/p>\n<p>PS: Za prepisane in narobe popravljene slike ne odgovarjam. Jokajte drugje! \ud83d\ude09<\/p>\n<p><!--more--><br \/>\n[python]<br \/>\n#!\/usr\/bin\/env python<\/p>\n<p>############################################################################<br \/>\n#    Copyright (C) 2008 by David Klasinc<br \/>\n#    bigwhale@lubica.net<br \/>\n#<br \/>\n#    This program is free software; you can redistribute it and#or modify<br \/>\n#    it under the terms of the GNU General Public License as published by<br \/>\n#    the Free Software Foundation; either version 2 of the License, or<br \/>\n#    (at your option) any later version.<br \/>\n#<br \/>\n#    This program is distributed in the hope that it will be useful,<br \/>\n#    but WITHOUT ANY WARRANTY; without even the implied warranty of<br \/>\n#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br \/>\n#    GNU General Public License for more details.<br \/>\n#<br \/>\n#    You should have received a copy of the GNU General Public License<br \/>\n#    along with this program; if not, write to the<br \/>\n#    Free Software Foundation, Inc.,<br \/>\n#    59 Temple Place &#8211; Suite 330, Boston, MA  02111-1307, USA.<br \/>\n############################################################################<\/p>\n<p>import os<br \/>\nimport sys<br \/>\nimport time<br \/>\nimport Image<br \/>\nimport shutil<br \/>\nimport pyexiv2<\/p>\n<p>from stat import *<\/p>\n<p>def avgPixel (pix1, pix2, pix3, pix4 = None):<br \/>\n    if pix4 == None:<br \/>\n        avg = ( (pix1[0] + pix2[0] + pix3[0]) \/ 3,<br \/>\n                (pix1[1] + pix2[1] + pix3[1]) \/ 3,<br \/>\n                (pix1[2] + pix2[2] + pix3[2]) \/ 3<br \/>\n            )<br \/>\n    else:<br \/>\n        avg = ( (pix1[0] + pix2[0] + pix3[0] + pix4[0]) \/ 4,<br \/>\n                (pix1[1] + pix2[1] + pix3[1] + pix4[1]) \/ 4,<br \/>\n                (pix1[2] + pix2[2] + pix3[2] + pix4[2]) \/ 4<br \/>\n            )<br \/>\n    return avg<\/p>\n<p>def fixPixel (inFileName):<\/p>\n<p>    if not os.path.exists (inFileName):<br \/>\n        print &#8220;Error: file not found:&#8221;, inFileName<br \/>\n        sysv.exit ()<br \/>\n    inImg = Image.open (inFileName)<br \/>\n    inMeta = pyexiv2.Image (inFileName)<br \/>\n    inMeta.readMetadata()<br \/>\n    tmpTime = inMeta[&#8216;Exif.Image.DateTime&#8217;]<br \/>\n    unixTime = time.mktime (tmpTime.timetuple())<\/p>\n<p>    #<br \/>\n    # Averaging pixel at 2058&#215;1468<br \/>\n    #<br \/>\n    pix1 = inImg.getpixel ((2058, 1467))<br \/>\n    pix2 = inImg.getpixel ((2057, 1468))<br \/>\n    pix3 = inImg.getpixel ((2059, 1468))<\/p>\n<p>    avg = avgPixel (pix1, pix2, pix3)<br \/>\n    inImg.putpixel ((2058,1468), avg)<\/p>\n<p>    #<br \/>\n    # Averaging pixel at 2057&#215;1469<br \/>\n    #<br \/>\n    pix1 = inImg.getpixel ((2056, 1469))<br \/>\n    pix2 = inImg.getpixel ((2057, 1468))<br \/>\n    pix3 = inImg.getpixel ((2057, 1470))<\/p>\n<p>    avg = avgPixel (pix1, pix2, pix3)<br \/>\n    inImg.putpixel ((2057,1469), avg)<\/p>\n<p>    #<br \/>\n    # Averaging pixel at 2058&#215;1470<br \/>\n    #<br \/>\n    pix1 = inImg.getpixel ((2057, 1470))<br \/>\n    pix2 = inImg.getpixel ((2058, 1471))<br \/>\n    pix3 = inImg.getpixel ((2059, 1470))<\/p>\n<p>    avg = avgPixel (pix1, pix2, pix3)<br \/>\n    inImg.putpixel ((2058,1470), avg)<\/p>\n<p>    #<br \/>\n    # Averaging pixel at 2059&#215;1469<br \/>\n    #<br \/>\n    pix1 = inImg.getpixel ((2059, 1468))<br \/>\n    pix2 = inImg.getpixel ((2060, 1469))<br \/>\n    pix3 = inImg.getpixel ((2059, 1470))<\/p>\n<p>    avg = avgPixel (pix1, pix2, pix3)<br \/>\n    inImg.putpixel ((2059,1469), avg)<\/p>\n<p>    #<br \/>\n    # Averaging final pixel at 2058&#215;1469<br \/>\n    #<br \/>\n    pix1 = inImg.getpixel ((2058, 1468))<br \/>\n    pix2 = inImg.getpixel ((2057, 1469))<br \/>\n    pix3 = inImg.getpixel ((2058, 1470))<br \/>\n    pix4 = inImg.getpixel ((2059, 1469))<\/p>\n<p>    avg = avgPixel (pix1, pix2, pix3, pix4)<br \/>\n    inImg.putpixel ((2058,1469), avg)<\/p>\n<p>    #<br \/>\n    # Save it and copy meta data!<br \/>\n    #<br \/>\n    inImg.save (inFileName, &#8220;JPEG&#8221;, quality = 99)<br \/>\n    inMeta.writeMetadata()<\/p>\n<p>    #<br \/>\n    # Preserve timestamp from EXIF!<br \/>\n    #<br \/>\n    os.utime(inFileName, (unixTime, unixTime))<\/p>\n<p>if __name__ == &#8216;__main__&#8217;:    <\/p>\n<p>    try:<br \/>\n        inFileName = sys.argv[1]<br \/>\n    except:<br \/>\n        print &#8220;Usage: pixfix <image>\\n&#8221;<br \/>\n        sys.exit ()<\/p>\n<p>    fixPixel (inFileName)<\/p>\n<p>    print &#8220;Done.&#8221;<br \/>\n[\/python]<br \/>\n<\/image><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ste kupili nov fotoaparat? Vam deluje? Ne? Ima en vro\u010d pixel? Kje pa je ta pixel? 2058&#215;1469? To\u010dno tam? In se razleze na \u0161tiri sosednje piksle? Brez panike! Uporabite PixFix! Popravil vam bo pixel na 2058&#215;1469, ter njegove \u0161tiri sosede! Veselite se! PS: Za prepisane in narobe popravljene slike ne odgovarjam. Jokajte drugje! \ud83d\ude09<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,7],"tags":[],"class_list":["post-1446","post","type-post","status-publish","format-standard","hentry","category-open-source","category-tech-stuff"],"_links":{"self":[{"href":"https:\/\/lubica.net\/bigwhale\/blog\/wp-json\/wp\/v2\/posts\/1446","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lubica.net\/bigwhale\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lubica.net\/bigwhale\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lubica.net\/bigwhale\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/lubica.net\/bigwhale\/blog\/wp-json\/wp\/v2\/comments?post=1446"}],"version-history":[{"count":0,"href":"https:\/\/lubica.net\/bigwhale\/blog\/wp-json\/wp\/v2\/posts\/1446\/revisions"}],"wp:attachment":[{"href":"https:\/\/lubica.net\/bigwhale\/blog\/wp-json\/wp\/v2\/media?parent=1446"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lubica.net\/bigwhale\/blog\/wp-json\/wp\/v2\/categories?post=1446"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lubica.net\/bigwhale\/blog\/wp-json\/wp\/v2\/tags?post=1446"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}