LoginSignup
1
1

More than 5 years have passed since last update.

画像や写真を、テレビに映ったように加工する方法。[python,PIL,tkinter使用]

Last updated at Posted at 2018-03-03

画像や写真を、テレビに映ったように加工するプログラムを書きました。

python テレビ.png

この画像を見てもらうと分かると思いますが、このようなテレビを近づいてみたときのような模様を再現するのが今回のプログラムです。

本来ならば1つのピクセルで3色分の情報を表現するところを、3種類のピクセルで3色の情報を表現しています。

以下がそのプログラムです。


from PIL import Image
import os, tkinter.filedialog, tkinter.messagebox

root = tkinter.Tk()
root.withdraw()
fTyp = [("","*")]
iDir = os.path.abspath(os.path.dirname(__file__))
tkinter.messagebox.showinfo('','テレビ風にしたい画像を選んでください')
file = tkinter.filedialog.askopenfilename(filetypes = fTyp,initialdir = iDir)

im = Image.open(file)
size =im.size
im2 = Image.new('RGB', size)

vr=70
for y in range(size[1]):
    for x in range(size[0]//3):

        r=(im.getpixel((x*3, y))[0]+im.getpixel((x*3+1, y))[0]+im.getpixel((x*3+2, y))[0])//3
        im2.putpixel((x*3, y), (r, vr, vr))

        g=(im.getpixel((x*3, y))[1]+im.getpixel((x*3+1, y))[1]+im.getpixel((x*3+2, y))[1])//3
        im2.putpixel((x*3+1, y), (vr, g, vr))

        b = (im.getpixel((x*3, y))[2]+im.getpixel((x*3+1, y))[2]+im.getpixel((x*3+2, y))[2])//3
        im2.putpixel((x*3+2, y), (vr, vr, b))

im2.show()
im2.save("TV01.png")

tkinter.messagebox.showinfo('',"テレビ風にして保存しました")

以上が「画像や写真を、テレビに映ったように加工する方法」でした。

 

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1