Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- Batch descreening of (indexed,b/w) scans in GIMP 2.6.
- Martin Ponweiser, 2012
- I needed this when I had lots of 600dpi B/W scans with black half-tone (=gray) text backgrounds
- and OCR in Acrobat therefore didn't work in these sections.
- Change default paths and descreen settings in "register()" section!
- Default input and output format is indexed TIFF.
- Copy this script into your plug-in folder and chmod to executable!
- Tested on Ubuntu 10.04.
- Requires descreen script and fourier plug-in:
- http://registry.gimp.org/node/24411
- http://www.albumartexchange.com/forums/viewtopic.php?f=2&t=1986
- Script based on:
- http://www.exp-media.com/content/extending-gimp-python-python-fu-plugins-part-4
- """
- import os, re, glob
- from gimpfu import *
- from gimpenums import *
- def plugin_main(globpattern, source_dir, target_dir, desc_sens, desc_selgrow, desc_ratiopres, desc_despeckle ):
- pdb.gimp_message("Globbing: " + source_dir + os.sep + globpattern)
- glob_result = pdb.file_glob(source_dir + os.sep + globpattern, 1)
- filecount = glob_result[0]
- for f in glob_result[1]:
- imagefile = f
- #pdb.gimp_message("Opening: " + imagefile)
- try:
- image = pdb.gimp_file_load(imagefile, imagefile)
- except:
- pdb.gimp_message("Error loading: " + imagefile)
- try:
- pdb.gimp_image_convert_rgb(image)
- #pdb.gimp_display_new(image)
- drawable = pdb.gimp_image_get_active_layer(image)
- pdb.script_fu_descreen(image, drawable, desc_sens, desc_selgrow, desc_despeckle, desc_ratiopres )
- pdb.gimp_image_convert_indexed(image, 0, 3, 0, FALSE, TRUE, "")
- except:
- pdb.gimp_message("Error processing: " + imagefile)
- try:
- outputfile = target_dir + os.sep + os.path.basename(imagefile)
- #pdb.gimp_message("Saving copy to: " + outputfile)
- if globpattern == "*.tiff":
- # compress as CCITT G4 Fax (6)
- pdb.file_tiff_save(image, drawable, outputfile, outputfile, 6)
- else:
- pdb.gimp_file_save(image, drawable, outputfile, outputfile)
- except:
- pdb.gimp_message("Error saving: " + imagefile)
- pdb.gimp_image_delete(image)
- return
- register(
- "batch_descreen",
- "Batch wrapper for descreen script.",
- "Batch wrapper for descreen script.",
- "Martin Ponweiser",
- "Martin Ponweiser",
- "2012-01-06",
- "<Toolbox>/Batch/Descreen...",
- #"INDEXED*",
- "",
- [
- (PF_STRING, "glob_pattern", "Glob Pattern", "*.tiff"),
- ## PF_DIRNAME defaults must end with /* or something else ?!
- (PF_DIRNAME, "source_directory", "Source Directory", "/home/mp/orig/input/*"),
- (PF_DIRNAME, "target_directory", "Target Directory", "/home/mp/orig/output/*"),
- (PF_FLOAT, "descreen_sensitivity", "Descreen: Sensitivity", 90),
- (PF_STRING, "descreen_selection_growth", "Descreen: Selection Growth", 4),
- (PF_STRING, "descreen_ratio_middle_preservation", "Descreen: Ratio for middle preservation", 3),
- (PF_BOOL, "descreen_despeckle", "Descreen: Despeckle afterwards?", TRUE),
- ],
- [],
- plugin_main)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement