Thread Rating:
  • 310 Vote(s) - 2.8 Average
  • 1
  • 2
  • 3
  • 4
  • 5
画像ファイルのモノクロ化
11-20-2013, 04:18 PM,
#1
画像ファイルのモノクロ化
お世話になります。

イメージファイルをダウンロードする際に画像をモノクロ化して取り込みたいと思っています。
いい方法はありますでしょうか?

ご教示 宜しくお願いします
11-27-2013, 09:29 AM, (This post was last modified: 11-27-2013, 09:42 AM by umemura.)
#2
RE: 画像ファイルのモノクロ化
ImageGraphic や、IMAGEFILTER にそれらしきものがないので、
直接 Pixelmap で変換しました。
グレースケール変換には単純平均を採用しています。

保存は、サンプルなので jpegにしか対応していませんが、
実際は、保存時の拡張子を選択させ、それに応じて、
ImageData.save-to-url のMIMEタイプを切り替えるとか必要かも知れませんね。

Code:
{def original-pm =  {Pixmap.from-url {url "http://www.fuji-kawaguchiko.com/images/p/008event/koyo/main.jpg"}}}

{def fr = {Frame}}

{CommandButton
    label = "保存",
    {on Action do

        def pm = {original-pm.clone}

        ||単純平均法でグレースケール変換
        {for x:int = 0 below pm.max-x  do
            {for y:int = 0 below pm.max-y do
                def px = {pm.get x, y} asa Pixel
                def new-y = (px.red + px.blue + px.green) / 3

                ||加重平均法
                ||def new-y = 0.298912 * px.red + 0.586611 * px.green  + 0.114478 * px.blue
                def new-px = {Pixel.create new-y, new-y, new-y}
                {pm.set x,y, new-px}
            }
        }
        ||保存(jpegのみ)
        {if-non-null u = {choose-file style = FileDialogStyle.save-as} then
            def id = {ImageData}
            set id.pixmaps = {{Array-of Pixmap} pm}
            {id.save-to-url u, "image/jpeg"}
            def ig = {ImageGraphic u}
            {fr.add ig, replace? = true}
        }
    }
}
{value fr}
11-29-2013, 04:08 PM,
#3
RE: 画像ファイルのモノクロ化
umemuraさま

いつもありがとうございます。

加重平均法、単純平均法なる方法も知りませんでした。

勉強になりました。

又 宜しくお願いします


Forum Jump:


Users browsing this thread:
1 Guest(s)

MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1017 - Can't find file: 'mybb_threadviews' (errno: 2)
Query:
INSERT INTO mybb_threadviews (tid) VALUES('1008')