2

Python で Gimp 用に記述された Scriptfu スクリプトがあり、既存の画像にいくつかの手順を適用し、その過程でインデックス付きの画像に変換します。結果の画像で最も明るい色は常にほぼ白です。真っ白にしたい。便利なことに、その最も明るい色は常にインデックス付きイメージのカラーマップの一番上の色なので、カラーマップの一番上の色を白に設定したいだけです。

カラーマップ(つまり、その中の色)の操作方法に関するAPIの説明には何も見つかりませんでした。そのため、現在、そのステップは常に手動で行っています(Windows→ドッキング可能なダイアログ→カラーマップ→一番上の色をクリック→テキストウィジェットに「ffffff」と入力します→ ダイアログを閉じる)。しかしもちろん、Scriptfu の全体的なアイデアは、いくつかのステップだけでなく、すべてのステップを自動化することです。

Python Scriptfu スクリプトからカラーマップにアクセスする方法を教えてもらえますか?

これが私の現在のコードです(それを行う方法についてのアイデアがないため、最後のステップを実行しようとさえしていません):

#!/usr/bin/env python

"""
paperwhite -- a gimp plugin (place me at ~/.gimp-2.6/plug-ins/ and give
              me execution permissions) for making fotographs of papers
              (documents) white in the background
"""

import math
from gimpfu import *

def python_paperwhite(timg, tdrawable, radius=12):
    layer = tdrawable.copy()
    timg.add_layer(layer)
    layer.mode = DIVIDE_MODE
    pdb.plug_in_despeckle(timg, layer, radius, 2, 7, 248)
    timg.flatten()
    pdb.gimp_levels(timg.layers[0], 0, 10, 230, 1.0, 0, 255)
    pdb.gimp_image_convert_indexed(timg,
        NO_DITHER, MAKE_PALETTE, 16, False, True, '')
    (bytesCount, colorMap) = pdb.gimp_image_get_colormap(timg)
    pdb.gimp_message("Consider saving as PNG now!")

register(
        "python_fu_paperwhite",
        "Make the paper of the photographed paper document white.",
        "Make the paper of the photographed paper document white.",
        "Alfe Berlin",
        "Alfe Berlin",
        "2012-2012",
        "<Image>/Filters/Artistic/Paperw_hite...",
        "RGB*, GRAY*",
        [
                (PF_INT, "radius", "Radius", 12),
        ],
        [],
        python_paperwhite)

main()
4

1 に答える 1

1

pdb.gimp_image_get_colormapとを使用するだけpdb.gimp_image_set_colormapです。

変更したいエントリが実際に常に最初にある場合は、次のように書くだけで十分です。

colormap = pdb.gimp_image_get_colormap(timg)[1]
colormap = (255,255,255) + colormap[3:]
pdb.gimp_image_set_colormap(timg, len(colormap), colormap)
于 2014-03-25T06:17:53.177 に答える