我有一个用Python为Gimp编写的Scriptfu脚本,它对现有图像应用几个步骤,并在此过程中将其转换为索引图像。结果图像中最亮的颜色总是接近白色;我希望将其设置为精确白色。方便地说,最亮的颜色总是索引图像的colormap中的最上面的颜色,所以我只想将colormap中最上面的颜色设置为白色。在
我在API描述中没有发现如何操作colormap(即其中的颜色),因此目前我一直手动执行步骤(Windows→Dockable Dialogs→colormap→单击最上面的颜色→在文本小部件中输入“ffffff”→关闭对话框)。当然,Scriptfu的全部想法是自动化所有步骤,而不仅仅是几个步骤。在
有谁能告诉我如何从pythonscriptfu脚本访问colormap吗?在
以下是我当前的代码(由于缺乏关于如何执行的想法,它甚至没有尝试执行最后一步):
#!/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()
只需使用
pdb.gimp_image_get_colormap
和pdb.gimp_image_set_colormap
。在如果要更改的条目确实总是第一个条目,则只需写下:
相关问题 更多 >
编程相关推荐