Gauche-CLを使って画像のサムネイルを作る方法です。元ネタはProgramming Computer Vision With Pythonから。
Gauche-CVはaharisuのごみ箱で公開されています。
Python PILでサムネイルを作る
thumbnail()を使います。画像を小さくするアルゴリズムを変更するには、'ANTIALIAS'の所を修正してください。
# -*- coding: utf-8 -*- __author__ = 'Natsutani' from PIL import Image def make_thumbnail(infile, outfile): try: im = Image.open(infile) im.thumbnail((128,128), getattr(Image, 'ANTIALIAS')) im.save(outfile) except Exception as ex: print(repr(ex)) print('thumbnail failed %s' % infile) def main(): make_thumbnail('twittan2.jpg', 'twittan2_thumb.jpg') if __name__ == "__main__": main()
Gauche-CVでサムネイルを作る
cv-resizeで画像を小さくできます。画像を小さくするアルゴリズムを変更するには、CV_INTER_LINEARの所を修正してください。
(use cv) (let* ((src (cv-load-image "twittan2.jpg")) (thumb (make-image 128 128 (ref src 'depth) (ref src 'n-channels)))) (cv-resize src thumb CV_INTER_LINEAR) (cv-save-image "twittan2_thumb_gcv.jpg" thumb))
処理結果
Gauche-CVの出力結果です。