问题描述
我需要比较需要堆叠大量图像的分割算法的结果 - 例如原始和二进制图像。所以我想到了一个GIMP脚本,它取一个目录的名称并将所有包含图像文件放入图层中,以便在GIMP中打开和关闭它们以比较结果。
如何使用GIMP实现这一目标?
感谢您的提示!
I need to compare the results of segmentation algorithms where lots of images need to be stacked - e.g. original and binary image. So I thought of a GIMP script which takes the name of a directory and puts all containing image files into layers so that they can be switched on and off in GIMP to compare results.How to achieve this with GIMP?Thank you for your tips!
问候
推荐答案
不使用script-fu。但Python适合您的需求。这是一个简单的脚本 - 核心逻辑应该是4行左右,所以我会在这里为你写一下:
"Not with script-fu". But Python is suitable to your needs. It is a simple script - the core logic should be 4 lines or so, therefore I will just write it here for you:
#!/usr/bin/python
# -*- coding: utf-8 -*-
from gimpfu import *
import os
def load_images_in_dir(image, drw, path):
for filename in os.listdir(path):
try:
if filename.lower().split(".")[-1] in ("png", "jpg"):
#import pdb as debug; debug.set_trace()
image_id, layer_ids = pdb.gimp_file_load_layers(image,
os.path.join(path, filename))
for id in layer_ids:
new_layer = gimp.Item.from_id(id)
pdb.gimp_image_add_layer(image, new_layer, 0)
except Exception, error:
print error
register(
"open_images_in_dir",
"Open all files in a directory",
"Open all files in a directory",
"Joao S. O. Bueno",
"Joao S. O. Bueno",
"2012. Creative Commons Citation Needed license",
"Open Images in Dir as Layers...",
"*",
[(PF_IMAGE, "image", "the image", None),
(PF_DRAWABLE, "drw", "the drawable", None),
(PF_DIRNAME,"path", "Directory to Open", "."),],
[],
load_images_in_dir,
menu="<Image>/File/")
main()
注意第二个部分代码只是注册函数的样板。
确实 - 调用gimp_file_load_layers不能正常工作 - 因为它返回一个对象id的列表,这些对象似乎不是来自Python - 但调用Item.from_id方法允许一个绕过这种不便。这只适用于gimp-2.8,但
Note that the second part of the code is just the boilerplate for registering a function.Indeed - the call "gimp_file_load_layers" does not work as it should - as it returns a list of object "id"s which are intended not to be seem from Python - but the call to "Item.from_id" method allows one to bypass this inconvenience. This is only available in gimp-2.8, though
为了让它在gimp 2.6中工作,你将不得不求助于在新图像中打开文件,然后复制图层到目标图像。
To get this to work in gimp 2.6 you will have to resort to open the file ina new image, and them copy the layer(s) to your target image.
将上面的脚本复制到GIMP的插件目录(在* nix,〜/ .gimp-2.8 / plug-ins下)例如 - 或检查编辑 - > prerencers-> GIMP中的文件夹以获取插件文件夹) - 并将其标记为可执行文件。
Copy the script above to a GIMP's plug-ins directory (under *nix, ~/.gimp-2.8/plug-ins, for example - or check edit->prerencers->folders within GIMP for a plug-in folder) - and mark it as executable.
这篇关于GIMP:从文件夹中的所有图像文件创建图像堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!