Пример #1
0
            y = i / width
            pix[x, y] = 255 if xs[i] == 1 else 0

    energy = E(xs, ys, width, height)
    print 0, energy

    for j in range(10):
        for i in range(S):
            if de(i): xs[i] = -xs[i]

        new_energy = E(xs, ys, width, height)
        print 1 + j, new_energy

        if energy - new_energy < EPS: break
        energy = new_energy

    reflect()
    return img


if __name__ == '__main__':
    infile = sys.argv[4]
    if len(sys.argv) == 6:
        outfile = sys.argv[5]
    else:
        outfile = None

    img = Image.open(infile)
    img2 = remove_noise(img)
    save_or_show(img2, outfile)
Пример #2
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from myutil import save_or_show

import Image
import ImageDraw
import ImageFont

if __name__ == '__main__':
    img = Image.new('1', (320, 180), "white") # 2値画像

    font = ImageFont.truetype('/Library/Fonts/sazanami-gothic.ttf', 48, encoding='utf-8')
    draw = ImageDraw.Draw(img)
    draw.text((20, 20), u'ぷるむる', font=font, fill='black')
    draw.text((20, 100), u'復々習レーン', font=font, fill='black')

    if len(sys.argv) == 2:
        outfile = sys.argv[1]
    else:
        outfile = None
    save_or_show(img, outfile)