Programming Computer Vision With Pythonを読み始めました。Pythonでそのまま画像処理をしても面白くないので、aharisuのごみ箱で公開されているGauce-CVを使ってみました。
Python PILで画像をモノクロにする。
Programming Computer Vision With Python に載っている方法です。convert('L')で変換しています。
# -*- coding: utf-8 -*- __author__ = 'Natsutani' from PIL import Image def conv_to_grayscale(infile, outfile): try: Image.open(infile).convert('L').save(outfile) except: print('cannot convert %s' % infile) def main(): conv_to_grayscale('twittan.jpg', 'twittan_g.jpg') if __name__ == "__main__": main()
Gauche-CVで画像をモノクロにする。
こちらでも簡単ですね。
(use cv) (let* ((src (cv-load-image "twittan.jpg")) (gray (make-image (ref src 'width) (ref src 'height) IPL_DEPTH_8U 1))) (cv-cvt-color src gray CV_BGR2GRAY) (cv-save-image "twittan_g.jpg" gray))
それTclで(ry
tcl好きの人のために。
package require Img image create photo im -file "twittan.jpg" im write "twittan_g.jpg" -grayscale puts im
Gauche-Tkで(ry
(ry
; tk の初期化 (use tk) (wish-path "wish") (with-module tk (set! *tk-debug* #t)) (tk-init '()) ; package と image コマンドを使えるようにする。 (define-tk-command tk-package package) (define-tk-command tk-image image) ; 実際の処理 (tk-package 'require 'Img) (tk-image 'create 'photo 'im :file "twittan.jpg") (tk-call 'im 'write "twittan_gg.jpg" '-grayscale) ; tkのウィンドウを閉じる (tk-shutdown)
処理結果
Gauche-CVの出力です。