Post Reply 

command-line optimizing

Jun 9, 2014, 08:37
Post: #1
command-line optimizing
Hi all,

after mixing-up multiple solutions, I finally got a batch command-line that performs my desired task. It runs on decent speed, but when I tried to process hundreds of files in one go, I would need to wait few minutes, so I'm wondering if the following command-line could be optimized, thank you.

Code:
for /f %f in ('dir /b c:\users\mini\desktop\testing') do "c:\program files\gimp 2\bin\gimp-console-2.8.exe" -i -d -f -s -b "(let* ((image (car (file-png-load 1 \"/Users/mini/Desktop/testing/%f\" \"/Users/mini/Desktop/testing/%f\") ) ) (drawable (car (gimp-image-active-drawable image ) ) ) ) (plug-in-colortoalpha 1 image drawable '(0 0 0) ) (gimp-file-save RUN-NONINTERACTIVE image drawable \"/Users/mini/Desktop/testing/%f\" \"/Users/mini/Desktop/testing/%f\") )" -b "(gimp-quit 0)"
Find all posts by this user
Quote this message in a reply
Jun 9, 2014, 10:57
Post: #2
RE: command-line optimizing
Looking at the examples on gimp org site

First,
Ensure you're using the correct/proper function names.
Go to www gimp org / tutorials/Basic_Batch/ if you haven't already.

For example, here in your code...
Code:
(let* ((image (car (file-png-load

Did you mean "cadr" ?
In Gimps' last batch example, here is their code

Code:
(define (batch-unsharp-mask pattern
                              radius
                              amount
                              threshold)
  (let* ((filelist (cadr (file-glob pattern 1))))
    (while (not (null? filelist))
           (let* ((filename (car filelist))
                  (image (car (gimp-file-load RUN-NONINTERACTIVE
                                              filename filename)))
                  (drawable (car (gimp-image-get-active-layer image))))
             (plug-in-unsharp-mask RUN-NONINTERACTIVE
                                   image drawable radius amount threshold)
             (gimp-file-save RUN-NONINTERACTIVE
                             image drawable filename filename)
             (gimp-image-delete image))
           (set! filelist (cdr filelist)))))

Last, try taking out one of each of the commands or using one at a time for each test run.

I see in your code you have all the commands at the start
Code:
... -i -d -f -s -b ...
Try one of the commands at a time with the exception of keeping the "-b" batch command in there to see if that speeds things up.

Hope this helps & if you get a new solution to it, please share so others can benefit ^_^

"In order to succeed, your desire for success should be greater than fear of failure." BC
[Image: 29uocaf.png]
iFS007 tut vids on YT ~ auto color B&W landscape tut
Visit this user's website Find all posts by this user
Quote this message in a reply
Jun 9, 2014, 13:03 (This post was last modified: Jun 9, 2014 15:19 by ofnuts.)
Post: #3
RE: command-line optimizing
(Jun 9, 2014 08:37)wmichaelv Wrote:  Hi all,

after mixing-up multiple solutions, I finally got a batch command-line that performs my desired task. It runs on decent speed, but when I tried to process hundreds of files in one go, I would need to wait few minutes, so I'm wondering if the following command-line could be optimized, thank you.

Code:
for /f %f in ('dir /b c:\users\mini\desktop\testing') do "c:\program files\gimp 2\bin\gimp-console-2.8.exe" -i -d -f -s -b "(let* ((image (car (file-png-load 1 \"/Users/mini/Desktop/testing/%f\" \"/Users/mini/Desktop/testing/%f\") ) ) (drawable (car (gimp-image-active-drawable image ) ) ) ) (plug-in-colortoalpha 1 image drawable '(0 0 0) ) (gimp-file-save RUN-NONINTERACTIVE image drawable \"/Users/mini/Desktop/testing/%f\" \"/Users/mini/Desktop/testing/%f\") )" -b "(gimp-quit 0)"

For this kind of work, a gew minutes on several hundreds of files is OK. Your limiting factor could be disk I/O.

Since this is some very simple processing, you can try to use ImageMagick and command line scripts instead (IM is significantly easier than Gimp for this kind of batch processing, and writing scripts on OSX is eaasier than on WIndows). If you are not limited by your disk I/O, using IM will let you use all cores of your machine, either because it can use them natively, or because you can run several scripts in parallel.

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Jun 9, 2014, 15:11
Post: #4
RE: command-line optimizing
If I read that correctly, you are starting and stopping GIMP for each file you process? In which case you are introducing a significant overhead and doing the process much slower than you need to.

It would be interesting to compare your method with a GIMP script that does it all in one go - and with a script written around multiple calls to ImageMagick for that matter.

Kevin
Find all posts by this user
Quote this message in a reply
Jun 9, 2014, 16:37 (This post was last modified: Jun 9, 2014 17:04 by rich2005.)
Post: #5
RE: command-line optimizing
Am I reading that correctly? It applies color-to-alpha to a png file?

You can do that within Gimp with the BIMP batch plugin.

The simplest IM command (white to transparent) is
convert input.png -transparent white output.png

edit:pulled that out of my notes and it produces an indexed png file.
for RGB it is
convert input.png -transparent white png24:output.png

** https://www.gimp-forum.net/ now answering questions**
Find all posts by this user
Quote this message in a reply
Jun 9, 2014, 19:11
Post: #6
RE: command-line optimizing
(Jun 9, 2014 15:11)paynekj Wrote:  If I read that correctly, you are starting and stopping GIMP for each file you process? In which case you are introducing a significant overhead and doing the process much slower than you need to.

Not that much actually, using -idfs he is skipping all the heavy stuff in the startup. And once the executable files have been loaded, if they are re-used pretty quickly (which is the case here) the second and next uses are near instantaneous, even on Windows.

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Jun 11, 2014, 03:13 (This post was last modified: Jun 11, 2014 03:13 by wmichaelv.)
Post: #7
RE: command-line optimizing
Thanks for the replies, all.

(Jun 9, 2014 13:03)ofnuts Wrote:  For this kind of work, a gew minutes on several hundreds of files is OK. Your limiting factor could be disk I/O.

Since this is some very simple processing, you can try to use ImageMagick and command line scripts instead (IM is significantly easier than Gimp for this kind of batch processing, and writing scripts on OSX is eaasier than on WIndows). If you are not limited by your disk I/O, using IM will let you use all cores of your machine, either because it can use them natively, or because you can run several scripts in parallel.

I've used IM for this task, but I haven't found the solution to reproduce the color-to-alpha effect from GIMP on IM yet, so I ended up using GIMP instead.

@rich2005
I've tried various IM scripts though none of them give a result as good as gimp.

btw, this is based on your simple script on black color:
http://puu.sh/9ohw6/1c401bbb12.jpg

@iForStyle007
The car and cadr are based on the script-fu.
May I know why you are recommending on using cadr instead of car?
Find all posts by this user
Quote this message in a reply
Jun 11, 2014, 08:26 (This post was last modified: Jun 11, 2014 13:16 by rich2005.)
Post: #8
RE: command-line optimizing
@wmichealv
hmm..never know what you are up against until you get a sample image and maybe still not exact.

The sample seems to have partial transparency and you get a reasonable result with

Code:
convert in.png -alpha set -channel RGBA -fill none -fuzz 30% -opaque black png24:out.png

more than 30% fuzz and you start removing bits of dark-red. Becoming almost as complicated as the gimp command line. As you say maybe not as good as gimp

The other suggestion was BIMP http://www.alessandrofrancesconi.it/projects/bimp/

looks like this

[Image: XTkNLdE.jpg]


comparison of results

[Image: A6CJ9RM.jpg]

edit: back to the original question -speed. Only a test with many images would determine.
I would think that IM would be quickest. Bimp is fast and of course flexible.

more edit: comparison speed test: 2097 100x100 tiles coloured with central black disk
read/write to the same hdd
BIMP 2 mins 20 seconds
IM 28 seconds including echoing the file name to show progress.

** https://www.gimp-forum.net/ now answering questions**
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Can't draw a clean line freehand Dave54 3 432 Jul 12, 2014 16:21
Last Post: Dave54
  How do I erase in a straight line? Terry50 2 797 May 12, 2014 03:11
Last Post: Terry50
  Can I make a line a specific size? jitter1127 3 1,073 Apr 25, 2014 08:58
Last Post: rich2005
  How to make line thicker? (Need advise) rangdaz 2 608 Feb 3, 2014 13:28
Last Post: rangdaz
  line spacing set to 0 but Gimp double spaces lines moltres_rider 2 486 Jan 15, 2014 15:52
Last Post: iForStyle007

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS