GIMP Forums

Full Version: batch despeckle
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'd like to get gimp to despeckle all images of one folder, with the options adaptive, recursive, Radius = 3, black level = -1 und white level = 256), afterwards save the images to another folder. Unfortunately I'm no programmer und don't get the tutorials to write a batch skript.
I know it should be

gimp -i -b '(skript "*.png" 1 2)' -b '(gimp-quit 0)'

[instead of 'skript' the despeckle funktion], but how to write it? And where to run the skript? In the folder, containing the gimp exe?

I'm thankful for any kind of help!

That should be relatively straightforward to do.

I'll try and write something later today, but it would be helpful to know what operating system you are using (Windows XP/Vista/7 Linux etc) and do you have Python support enabled in GIMP?

Thanks Kevin!

I use windows and don't have python on my PC.
There already is a despeckle plugin on e can find in the skript-fu repository. That works fine for me from the gimp GUI. I now only need to run it in batch mode. Maybe it isn't necessary to programm something new but to simply get it run from the command line? But how?
Thanks for any help!

It is necessary to write something new, and I've attached my attempt at it. Sorry it's a zip file but this forum doesn't allow me to attach the .scm file Huh

The zip file also contains a DOS batch file that has the command line in it:
"C:\Program Files\GIMP-2.0\bin\gimp-2.6.exe" -i -f -d --verbose -b "(kkiel_batch_despeckle \".png\" \"despeckle\")" -b "(gimp-quit 0)"

Although you may have to alter the path to the GIMP executable.

Note, the script will not work if the destination directory doesn't exist.

Hi Kevin,

this looks great (in notepad), thank you very very much! I'll test it this evening (after doing some backups ...) and tell you how it went.

Thank you very much again,

Hi Kevin,
I copied the .scm-file into the gimp skripts folder, opend skript-fu via the filter menu, clicked refresh
skripts afterwards, but it doesn't show up in the skripts list. Was this the wrong way to deal with it?
Then, I don't get from where to start the DOS batch file. Where are the image files expected to be?
Thanks a lot!
Correct me if I'm wrong but you asked for a batch file, not a script to be run interactively? So for a batch file you don't start gimp - the batch file does that.

Put the DOS batch file into the folder where your images are. Create a folder in the same directory called despeckle and then run the batch file by double-clicking on it.

Hi Kevin,

since the skript was an scm, not an exe, I thought it should be started from gimp. Anyway - your skript runs smoothly! I really am thankful, this saves me weeks of work!

Hi Kevin and other readers looking for a solution for the despeckle problem:

The skript still works fine and the despeckling effect is just what I need, but Gimp destroys the iptc-data and maybe some other metadata (icc profile). My despeckled images wont show up in Lightroom and Faststone, though other readers (irfanview, imatch, xnview) don't have problems .
So I won't be able to use it like that. Does anybody know how to avoid that? Is it another line of code in the skript? There must be some metadata skripts in Gimp.
Thanks for any help!

Your problem is that you are using PNG and there is no provision for EXIF/IPTC/XMP in this format... There is only a provision for a generic text comment (and Gimp seems to have the code to support that).

So you have two solutions:

1) Use high quality JPEG. Yes, JPEG is a lossy format, but at hight quality the loss is negligible for most purposes(*), and in any case if would be far less than what you lose in the despeckling anyway... You could also use TIFF (which is a lossless format fit to save "natural" images, and also supports EXIF/TIFF/XMP). Gimp normally keeps these metadata for these formats.

2) use some command line utility to copy metadata between original and processed files.

(*) There is a lot of paronoia about data loss in JPEG. The usual argument is that you lose some each time you edit the file. This is untrue... The JPEG algorithm, when implemented properly, is stable. The decoded pixels are reencoded with the same values so there is zero loss. Change occurs when the computation is different which happens when:

1) Quality settings are changed, but this is in general for a lesser quality
2) General color processing is applied. Loss due to JPEG is smaller that the round-off errors caused by the 8-bit processing in Gimp.
3) File is cropped on a boundary that displaces the 8x8 pixels blocks.

In other cases, where only local edit is performed, unchanged pixels get reencoded with the same values, so the loss is restricted to the one caused by the original encoding.
Hi Ofnuts,

thank you for your prompt reply. My images are saved as tif, lzw-compressed, grayscale mode. I thus changed the command line in the dos batch file.
Are there other ways I messed the meta-data up?

Thank you!

You didn't mess anything up. GIMP doesn't handle IPTC data at all. It gets dis-guarded when GIMP loads the image.

The only way other people have solved this problem is to use another tool to copy the meta-data out of the images before processing, then write it into the images after processing:
Hi paynekj,

I can afford to loose the IPTC-data because I can easily write them back with IMatch but what bothers me is that the images wont show up as a Lightroomthumbnail before importing ('no preview available') and as a Faststone thumbnail (thumbnails turn black). After importing to Lightroom though they are visible and Faststone will process the images further (lzw-compressing for example) without problems (though lightroom will have problems to show the previews of those before importing). I just want to make sure that standard image viewers will be able to cope with my images and that no seminal image information (icc profile, whatever) got lost.
So I will do some more checking before despeckling thousands of images ...
Thanks for your help!

Reference URL's