【问题标题】:GIMP: Create image stack from all image files in folderGIMP:从文件夹中的所有图像文件创建图像堆栈
【发布时间】:2012-06-15 11:01:29
【问题描述】:

我需要比较需要堆叠大量图像的分割算法的结果 - 例如原始图像和二进制图像。所以我想到了一个 GIMP 脚本,它采用目录的名称并将所有包含的图像文件放入图层中,以便可以在 GIMP 中打开和关闭它们以比较结果。 如何使用 GIMP 实现这一目标? 感谢您的提示!

问候

【问题讨论】:

    标签: image-processing gimp script-fu


    【解决方案1】:

    “不使用 script-fu”。但是 Python 适合您的需求。这是一个简单的脚本——核心逻辑应该是4行左右,所以我就写在这里给你吧:

    #!/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”列表,这些对象“id”不应该来自Python-但是对“Item.from_id”方法的调用允许绕过这个不便。不过,这仅在 gimp-2.8 中可用

    要让它在 gimp 2.6 中工作,您将不得不求助于在新图像中打开文件,然后他们将图层复制到您的目标图像。

    将上面的脚本复制到 GIMP 的插件目录(例如,在 *nix 下,~/.gimp-2.8/plug-ins 下 - 或检查 GIMP 中的 edit->prerencers->folders 以获取插件文件夹) - 并将其标记为可执行文件。

    【讨论】:

    • 您将如何更改此标题,是否可以在保存的文件中存储其他数据?
    【解决方案2】:

    我刚刚意识到 gimp 2.8 中的“文件”>“作为图层打开”命令可以完成类似的工作!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-16
      • 2021-07-12
      • 2016-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多