2012-06-12 60 views
2

我需要比較需要堆疊大量圖像的分割算法的結果 - 例如,原始和二進制圖像。所以我想到了一個GIMP腳本,該腳本取得一個目錄的名稱並將所有包含的圖像文件放入圖層,以便可以在GIMP中打開和關閉它們以比較結果。 如何用GIMP實現這一點? 謝謝你的提示!GIMP:從文件夾中的所有圖像文件創建圖像堆棧

Regards

回答

3

「not with 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」的列表,這些列表不希望看起來像Python - 但是對「Item.from_id」方法的調用允許其繞過這種不便。這隻適用於gimp-2.8,不過

爲了讓它在gimp 2.6中運行,你將不得不求助於在新圖像中打開文件,然後將圖層複製到目標圖像。

將上面的腳本複製到GIMP的插件目錄(例如,* nix,〜/ .gimp-2.8 /插件,或者在GIMP中檢查edit-> prerencers->文件夾以獲得插件文件夾) - 並將其標記爲可執行文件。

3

我剛剛意識到,在gimp 2.8中命令「file」>「open as layers」做類似的工作!

相關問題