我有一個用Python編寫的Gimp Scriptfu腳本,它在現有圖像上應用幾個步驟並將其轉換爲過程中的索引圖像。最終圖像中最亮的顏色總是接近白色;我想把它設置爲,正好是白色。方便的是,最亮的顏色始終是索引圖像色彩圖中最上面的顏色,所以我只想將色彩圖中最上面的顏色設置爲白色。Gimp,Script-Fu:我如何直接在顏色表中設置一個值
我在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()
只是爲了記錄在案,在GIMPland,我們通常保留術語「劇本福」來寫的代碼在Scheme(語言)中。一個Python腳本可以被稱爲「Python-fu」(儘管我更喜歡將它簡稱爲GIMP的Python腳本) – jsbueno
這是我第一次使用Gimp並且是該主題的全新腳本,我一定會犯這樣的錯誤,謝謝澄清! – Alfe