Advertisement
APlayer

batch-descreen.py

Jan 6th, 2012
1,547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.28 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Batch descreening of (indexed,b/w) scans in GIMP 2.6.
  5. Martin Ponweiser, 2012
  6.  
  7. I needed this when I had lots of 600dpi B/W scans with black half-tone (=gray) text backgrounds
  8. and OCR in Acrobat therefore didn't work in these sections.
  9.  
  10. Change default paths and descreen settings in "register()" section!
  11. Default input and output format is indexed TIFF.
  12. Copy this script into your plug-in folder and chmod to executable!
  13.  
  14. Tested on Ubuntu 10.04.
  15. Requires descreen script and fourier plug-in:
  16.    http://registry.gimp.org/node/24411
  17.    http://www.albumartexchange.com/forums/viewtopic.php?f=2&t=1986
  18.  
  19. Script based on:
  20.    http://www.exp-media.com/content/extending-gimp-python-python-fu-plugins-part-4
  21. """
  22.  
  23. import os, re, glob
  24. from gimpfu import *
  25. from gimpenums import *
  26.  
  27. def plugin_main(globpattern, source_dir, target_dir, desc_sens, desc_selgrow, desc_ratiopres, desc_despeckle ):
  28.     pdb.gimp_message("Globbing: " + source_dir + os.sep + globpattern)
  29.     glob_result = pdb.file_glob(source_dir + os.sep + globpattern,  1)
  30.     filecount = glob_result[0]
  31.     for f in glob_result[1]:
  32.         imagefile = f
  33.         #pdb.gimp_message("Opening: " + imagefile)
  34.         try:
  35.             image = pdb.gimp_file_load(imagefile,  imagefile)
  36.         except:
  37.            pdb.gimp_message("Error loading: " + imagefile)
  38.  
  39.         try:
  40.             pdb.gimp_image_convert_rgb(image)
  41.             #pdb.gimp_display_new(image)
  42.             drawable = pdb.gimp_image_get_active_layer(image)
  43.  
  44.             pdb.script_fu_descreen(image, drawable, desc_sens, desc_selgrow, desc_despeckle, desc_ratiopres )
  45.             pdb.gimp_image_convert_indexed(image, 0, 3, 0, FALSE, TRUE, "")
  46.         except:
  47.             pdb.gimp_message("Error processing: " + imagefile)
  48.  
  49.         try:
  50.             outputfile = target_dir + os.sep + os.path.basename(imagefile)
  51.             #pdb.gimp_message("Saving copy to: " + outputfile)
  52.             if globpattern == "*.tiff":
  53.                 # compress as CCITT G4 Fax (6)
  54.                 pdb.file_tiff_save(image,  drawable,  outputfile,  outputfile, 6)
  55.             else:
  56.                 pdb.gimp_file_save(image,  drawable,  outputfile,  outputfile)
  57.         except:
  58.             pdb.gimp_message("Error saving: " + imagefile)
  59.         pdb.gimp_image_delete(image)
  60.     return
  61.    
  62. register(
  63.     "batch_descreen",
  64.     "Batch wrapper for descreen script.",
  65.     "Batch wrapper for descreen script.",
  66.     "Martin Ponweiser",
  67.     "Martin Ponweiser",
  68.     "2012-01-06",
  69.     "<Toolbox>/Batch/Descreen...",
  70.     #"INDEXED*",
  71.     "",
  72.     [
  73.         (PF_STRING, "glob_pattern", "Glob Pattern", "*.tiff"),
  74.         ## PF_DIRNAME defaults must end with /* or something else ?!
  75.         (PF_DIRNAME, "source_directory", "Source Directory", "/home/mp/orig/input/*"),
  76.         (PF_DIRNAME, "target_directory", "Target Directory", "/home/mp/orig/output/*"),
  77.         (PF_FLOAT, "descreen_sensitivity", "Descreen: Sensitivity", 90),
  78.         (PF_STRING, "descreen_selection_growth", "Descreen: Selection Growth", 4),
  79.         (PF_STRING, "descreen_ratio_middle_preservation", "Descreen: Ratio for middle preservation", 3),
  80.         (PF_BOOL, "descreen_despeckle", "Descreen: Despeckle afterwards?", TRUE),
  81.     ],
  82.     [],
  83.     plugin_main)
  84.  
  85. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement