It is currently Fri Apr 26, 2024 12:18 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 19 posts ] 
Author Message
 Post subject: G'Mic montage from Command Line returning errors
PostPosted: Sun Mar 01, 2015 7:13 pm  (#1) 
Offline
GimpChat Member

Joined: Mar 01, 2015
Posts: 17
I'm trying to use G'Mic with montage from the command line. I run Linux Mint 17.1, 64-bit. My GIMP version is 2.8.10 and my GMic version is 1.6.0.4.

I followed directions at SourceForge (the forum isn't allowing me to post the URL).

I ran GIMP in verbose mode and found the output of the command I want to use:

[gmic_gimp]./apply/ -v -99 -gimp_montage 4,"V(H(0,1),H(2,V(3,4)))",1,0.5,3,0,0,0,0,255,0,0,0,0

I then converted the command into the format that the tutorial recommends for multiple images:

for i in *jpg
do
gmic $i -gimp_montage 4 "V(H(0,1),H(2,V(3,4)))" 1,0.5,3,0,0,0,0,255,0,0,0,0 -o processed_$i
done

I ran the above command on a folder of images and got the following error:

*** Error in ./ *** Unknown command or filename '-gimp_montage'.

I then read somewhere that I need to download the .update1582.gmic file, so I went to SourceForge and saved the file into my home directory and then ran the modified command:

for i in *jpg
do
gmic $HOME/.update1582.gmic $i -gimp_montage 4 "V(H(0,1),H(2,V(3,4)))" 1,0.5,3,0,0,0,0,255,0,0,0,0 -o processed_$i
done

It returned this error:

*** Error in ./ *** Command '-gimp_montage': Undefined argument '$3', in expression '$3' (for 2 arguments specified).

Can somebody help me to use G'Mic from the command line?


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: G'Mic montage from Command Line returning errors
PostPosted: Sun Mar 01, 2015 11:40 pm  (#2) 
Offline
GimpChat Member
User avatar

Joined: Mar 15, 2014
Posts: 115
Location: Brooklyn, NY
@serche
Welcome to Gimp Chat!

Nowadays, the gmic -update command automatically fetches the correct .updateXXXX.gmic for your version of gmic XXXX (currently 1.6.0.4). The same update occurs when you click on the circular arrow icon in the Gimp-G'MIC plug in. Furthermore, the .updateXXXX.gmic command is automatically included now, so you don't need to explicitly include the file on your command line. You should delete .update1582.gmic as that is quite old and just run the gmic -update command or refresh through the Gimp-G'MIC plug-in.

I believe you are suffering from slight transcription errors in your shell script. In transcribing from the verbose output given by Gimp:
Quote:
[gmic_gimp]./apply/ -v -99 -gimp_montage 4,"V(H(0,1),H(2,V(3,4)))",1,0.5,3,0,0,0,0,255,0,0,0,0

to your shell script, the comma after the 4 was inadvertently omitted, as was the comma after the closing double quote. With that space character following numeral four, the gmic command processor took the next block of characters to be another item and decided your '4' was the only parameter for gimp_montage. It then yelled at you for not furnishing enough parameters to gimp_montage.

Once you get the commas back in, you may need to escape the commas within the double quoted string using a '\' character. Try it without escaping first, but apply the backslash if your next error is about unbalanced parentheses.

Hope this helps! Keep us posted!

Garry


Top
 Post subject: Re: G'Mic montage from Command Line returning errors
PostPosted: Mon Mar 02, 2015 12:09 am  (#3) 
Offline
GimpChat Member

Joined: Mar 01, 2015
Posts: 17
Thanks for the help Garry!

I opened up Gimp and the G'Mic plugin and updated the plugin using the update button. Then I closed Gimp and tried the following commands.

I tried running this command:

for i in *jpg
do
gmic $i -gimp_montage 4,"V(H(0,1),H(2,V(3,4)))",1,0.5,3,0,0,0,0,255,0,0,0,0 -o processed_$i
done

It returned the error:

[gmic] *** Error in ./ *** Unknown command or filename '-gimp_montage'.

Then i ran the command:

for i in *jpg
do
gmic $i -gimp_montage 4,"V(H(0\1)\H(2\V(3\4)))",1,0.5,3,0,0,0,0,255,0,0,0,0 -o processed_$i
done

And it returned the same error as above.

EDIT: I just ran this command:

for i in *jpg
do
gmic $HOME/.update1610.gmic $i -gimp_montage 4,"V(H(0\1)\H(2\V(3\4)))",1,0.5,0,2,0,0,0,255,0,0,0,0 -o processed_$i
done

And it just made copies of all the pics in the folder. It didn't convert them to a montage.

This command just made a copy of one of the pictures in the folder, but no montage.

for i in *jpg
do
gmic $HOME/.update1610.gmic $i -gimp_montage 4,"V(H(0\1)\H(2\V(3\4)))",1,0.5,0,2,0,0,0,255,0,0,0,0 -o processed.jpg
done

Of course, I don't need the update1610 file, as you said, but I wonder why it at least gives me some output, whereas when I don't use it (or the 1582 update file) I just get errors.


Top
 Post subject: Re: G'Mic montage from Command Line returning errors
PostPosted: Mon Mar 02, 2015 2:41 am  (#4) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
Hi Serche,

There are probably several problems here for you.
You've said you have G'MIC 1.6.0.4 installed, but from the tests you've shown with the cli tool 'gmic', I have the impression that 1.6.0.4 is probably only the version of your plug-in, not your command line tool, because the command '-gimp_montage' has been added quite a long time ago. So, even without the additional update file, your 'gmic' should recognize it.
Could you check the version number of the cli tool by typing:

$ gmic -version


Also, the second problem is : your montage filter needs all input images at once to be able to generate the montage. The bash loop you are using is nice when you want to apply one filter independently on each image, but in your case, you have a filter with N image inputs and only one output, so only one invokation of 'gmic' is necessary. To include several images in G'MIC, just put the list of their names before calling the command. Also, as you are calling the G'MIC command from a shell (which has its own substitution mechanism), you have to backslash the double quotes and parentheses, like this probably:

$ gmic *.jpg -gimp_montage 4,\""V(H(0,1),H(2,V(3,4)))"\",1,0.5,3,0,0,0,0,255,0,0,0,0 -o processed.jpg


In the code above, I don't backslash all parentheses but put the expression between double quotes instead. That has the same effect in bash.

Let me know if that helps!


Top
 Post subject: Re: G'Mic montage from Command Line returning errors
PostPosted: Mon Mar 02, 2015 3:01 am  (#5) 
Offline
GimpChat Member

Joined: Mar 01, 2015
Posts: 17
Wow tx, Ronounours! I had command line G'Mic version 1.5.7.1 installed, so I updated it to 1.6.0.4.

And I just ran your command, and it worked!


Top
 Post subject: Re: G'Mic montage from Command Line returning errors
PostPosted: Mon Mar 02, 2015 4:39 am  (#6) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
Good news ! I like when a problem can be solved easily :)


Top
 Post subject: Re: G'Mic montage from Command Line returning errors
PostPosted: Mon Mar 02, 2015 9:36 am  (#7) 
Offline
GimpChat Member
User avatar

Joined: Mar 15, 2014
Posts: 115
Location: Brooklyn, NY
Hello serche,
So do I. I'm overjoyed when entire problems raise their ugly heads and are knocked down by Ronounours whilst I enjoy a nice night's sleep. That's the advantage of being six time zones behind him. I wake up and it's a green board and that leaves me more time to pontificate. I pray that he never moves to Brooklyn, or, worse yet, Hawai'i (which offers more temptations than Brooklyn and is a lot of time zones behind).

So, to pontification. I think the link you tried to post, but couldn't because you were still in Gimp Chat Purgatory, was "The command line behind the Gimp plug-in", a bridge that Ronounours and Zonderr wrote. It's a nice entry point into "G'MIC - The Command Line" because that's the way to find the script that implements the Gimp-G'MIC filter that so enchants you. I think that's where you got your shell script.

I've nothing against shell scripting in and of it self, but generally am cautious about mixing language environments, and I don't do it if I don't have to. There is no particular reason to use a shell script just for its programming logic, because the gmic language implements decision making and iteration as well, and its constructs are quite robust. Everything in that shell script can be re-written gmic-cally, and you are immediately rescued from all these cross-environment substitution issues.

With that wiki article you quoted are a few others:
  1. Custom commands
  2. Introduction to the G'MIC command line tool 'gmic'
  3. Using commands arguments and variables
  4. How to create a custom filter in the G’mic plug-in
  5. Making better custom filters
There are more instructional articles at the G'MIC Wiki, and a (still incomplete!) introduction to G'MIC at the G'MIC Tutorial Pages. These attempt to describe the gmic language in the larger mathematical and computer science setting that we play in. If you are new to this field, it is well worth your time to explore there (Well, at least I think so ;) . )

Last (but certainly!) not least, there is the update file itself, .updateXXXX.gmic where you can find the implementation of every Gimp-G'MIC filter, many G'MIC commands and some utilities besides. Among other things, there is a web site scraper in there. I wouldn't dive into the update file right off, but once you've become comfortable with the basics, written a few custom gmic commands, and are feeling ready to take flight, that becomes your primary Go To Resource. I'm poking around in it nearly every day, myself.

Finally, I think pretty much everybody who is writing, or has written, a Gimp-G'MIC filter of some sort hangs out here on a daily, weekly, or monthly basis. So if there is some technique that seems beyond your ken, or some Gimp-G'MIC filter that intrigues you, chances are you can rouse up the author here (and chances are, the author is Ronounours!).

That's my pontification of the day. Have fun with Gimp-G'MIC; show us some of your stuff!

Garry


Top
 Post subject: Re: G'Mic montage from Command Line returning errors
PostPosted: Tue Mar 03, 2015 8:25 am  (#8) 
Offline
GimpChat Member

Joined: Mar 01, 2015
Posts: 17
Thanks for the tutorial links, grosood! I'll check them out. You're right about the link I used for the script.

I've been having a lot of fun with this tool.

For those interested I've converted the G'Mic command for use with Custom Actions in the Thunar file manager.

Name: Montage - 75% Scale, 5px Frame

The Command:

for file in %N; do gmic %N -gimp_montage 4,\""V(H(0,1),H(2,V(3,4)))"\",1,0.75,0,5,0,0,0,255,0,0,0,0 -o --0000.jpg

Appearance Conditions: Select image files.

The command for Montage - 50% Scale, 5px Frame:

for file in %N; do gmic %N -gimp_montage 4,\""V(H(0,1),H(2,V(3,4)))"\",1,0.5,5,0,0,0,0,255,0,0,0,0 -o --0000.jpg

The command for Montage - 100%, 5px Frame:

for file in %N; do gmic %N -gimp_montage 4,\""V(H(0,1),H(2,V(3,4)))"\",1,1.0,0,5,0,0,0,255,0,0,0,0 -o --0000.jpg

Now I can just right click on a bunch of images and click the custom action and the montage is created without the need to use the command line.

I don't know if the creator has thought about this, but it would be useful to "market" this tool as a way to create contact sheets of video files. The tool would probably have to be modified a bit so that frames could be skipped, but it would work well I think. I just tried using the Thunar G'Mic Custom Action on an 2 second MP4 video file and G'Mic successfully converted it to a montage. It also works on animated gif files. See examples attached.


Attachments:
--0000.jpg
--0000.jpg [ 3.58 MiB | Viewed 4686 times ]
--0000.jpg
--0000.jpg [ 4.93 MiB | Viewed 4686 times ]
--0000a.jpg
--0000a.jpg [ 247.2 KiB | Viewed 4686 times ]
Top
 Post subject: Re: G'Mic montage from Command Line returning errors
PostPosted: Tue Mar 03, 2015 10:34 am  (#9) 
Offline
GimpChat Member
User avatar

Joined: Mar 15, 2014
Posts: 115
Location: Brooklyn, NY
Hi serche,

And thank you for the tip on the Thunar Custom Action! I didn't know about custom actions, and what you've taught me here is immediately useful. I can use that in tons of different ways. :bigthup

G'MIC is very video friendly. A G'MIC image natively has width, height and depth, so video footage just looks like one image to G'MIC, and most G'MIC commands work natively in all the cardinal dimensions of width, height and depth. Here is a piece demonstrating the concept: Cauldron, Anyone?

G'MIC has a rich selection syntax; these appearing in square brackets following commands. You've probably seen -foo[-1] (operates only on the last image in the list) or -foo[0] (operates only on the first). The syntax, however is quite rich. Here's a use case that is quite common for me. I want to make a story board from existing footage. About one frame per second is about right. Let's assume the footage runs at 24 frames per second. The command -keep[0--1:24] will drop all frames off the image list except for those where the frame number modulo 24 is zero. See Command Decorations for an introduction to the syntax.

Thanks again for the Thunar tip!

Garry


Top
 Post subject: Re: G'Mic montage from Command Line returning errors
PostPosted: Wed Mar 04, 2015 12:02 pm  (#10) 
Offline
GimpChat Member

Joined: Mar 01, 2015
Posts: 17
Thanks Garry! Could you give me an example of a G'Mic command that would create a contact sheet for a video?

Also, when creating montages of a series of images sometimes G'Mic will loop the operation many times, instead of just stopping after it does it once. This isn't apparent when the images have a small file size, but it becomes apparent when the images have a large size (above 1mb) and it can freeze my system.

This is the command I'm using:

for file in %N; do gmic %N -gimp_montage 4,\""V(H(0,1),H(2,V(3,4)))"\",1,0.3,5,0,0,0,0,255,0,0,0,0 -o 0000aa.jpg

Is there some modification I can make to that command that will get G'Mic to stop performing the same operation multiple times?

Incidentally it may be a problem with my Thunar command, because when I run the following command from the command line on a set of the same images it stops after completing the operation a single time:

gmic *.jpg -gimp_montage 4,\""V(H(0,1),H(2,V(3,4)))"\",1,0.5,3,0,0,0,0,255,0,0,0,0 -o processed.jpg


Top
 Post subject: Re: G'Mic montage from Command Line returning errors
PostPosted: Wed Mar 04, 2015 12:17 pm  (#11) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
serche, I think you don't need a loop over your images, if you want a single montage.
Just remove the loop 'for file in %N', because you are computing N times the same montage, where N is your number of input images.


Top
 Post subject: Re: G'Mic montage from Command Line returning errors
PostPosted: Wed Mar 04, 2015 12:31 pm  (#12) 
Offline
GimpChat Member

Joined: Mar 01, 2015
Posts: 17
Ahh thanks Ronounours!

So this is the best Thunar Custom Action command (in this example 30% resizing and 5px framing):

gmic %N -gimp_montage 4,\""V(H(0,1),H(2,V(3,4)))"\",1,0.3,5,0,0,0,0,255,0,0,0,0 -o 0000aa.jpg


Top
 Post subject: Re: G'Mic montage from Command Line returning errors
PostPosted: Thu Mar 05, 2015 6:43 am  (#13) 
Offline
GimpChat Member

Joined: Mar 01, 2015
Posts: 17
Why is it that the montage is a larger file size than the size of the images that make it up? I convert 10 images that amount to 1.3mb total, and the resulting montage will be 6mb or thereabouts. Is there a setting that can make the montage the same file size as the source images?

Testing:

10 images amounting to 1.3 mb.

Resulting montage:

100% scale=6.5mb
75% scale = 5.6mb
50% scale=3.7mb
30% scale=1.4mb

So to have the montage approximate the size of the combined images I need to use 30% scale. Ideally I'd like to use the 100% scale and have the montage be approximately the same size as the combined source images.

EDIT: I have found that a good solution to large montage file sizes is to convert the jpg montage to webp at 90 quality. It cuts the size down to less than the size of the combined images and the image still looks good. I guess I could create the montage using the webp format instead a jpeg.


Top
 Post subject: Re: G'Mic montage from Command Line returning errors
PostPosted: Thu Mar 05, 2015 7:02 am  (#14) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
I suppose you have used .jpg as the output format ?
If so, G'MIC saves by default at 100% quality, so the resulting jpeg files can be large.
You can specify the output quality (so, related to the compression ratio) when you save a .jpg file.
Just use
-o file.jpg,75

to specify a 75% quality for the output file 'file.jpg'.


Top
 Post subject: Re: G'Mic montage from Command Line returning errors
PostPosted: Thu Mar 05, 2015 8:53 am  (#15) 
Offline
GimpChat Member

Joined: Mar 01, 2015
Posts: 17
Tx! Though I find I get better results by saving as jpg at 100% quality, and then converting the montage to webp at 90 quality.


Top
 Post subject: Re: G'Mic montage from Command Line returning errors
PostPosted: Thu Mar 05, 2015 8:25 pm  (#16) 
Offline
GimpChat Member

Joined: Mar 01, 2015
Posts: 17
Here's the Thunar Custom Action to create a contact sheet from a video, with 1 frame every second:

gmic %N -keep[0--1:24] -gimp_montage 4,\""V(H(0,1),H(2,V(3,4)))"\",1,1.0,0,5,0,0,0,255,0,0,0,0 -o -0000capture.jpg

I can modify this at some point to work with YAD or Zenity, so a box pops up asking for a custom frame capture.


Top
 Post subject: Re: G'Mic montage from Command Line returning errors
PostPosted: Fri Mar 06, 2015 3:14 am  (#17) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
@serche : the problem with your latest command (for the videos) is that G'MIC first loads all video frames in memory, and then discard 23/24 of them, which is not really optimal in term of memory consumption.
You should instead load only 1/24 frames of the video files, like this :
gmic %N,0,-1,24 -gimp_montage 4,\"\",1,1.0,0,5,0,0,0,255,0,0,0,0 -o -0000capture.jpg



EDIT: I've just discovered a bug that causes G'MIC to hand if the video does not have a number of frames which is a multiple of 24. I've found a fix, but I need to release new binaries to make it working for everyone.

EDIT2: I've build new beta packages with the fix included, available on the G'MIC sourceforge file server : https://sourceforge.net/projects/gmic/files/beta/


Top
 Post subject: Re: G'Mic montage from Command Line returning errors
PostPosted: Mon Mar 09, 2015 12:28 pm  (#18) 
Offline
GimpChat Member

Joined: Mar 01, 2015
Posts: 17
Ronounours wrote:
@serche : the problem with your latest command (for the videos) is that G'MIC first loads all video frames in memory, and then discard 23/24 of them, which is not really optimal in term of memory consumption.
You should instead load only 1/24 frames of the video files, like this :
gmic %N,0,-1,24 -gimp_montage 4,\"\",1,1.0,0,5,0,0,0,255,0,0,0,0 -o -0000capture.jpg



EDIT: I've just discovered a bug that causes G'MIC to hand if the video does not have a number of frames which is a multiple of 24. I've found a fix, but I need to release new binaries to make it working for everyone.

EDIT2: I've build new beta packages with the fix included, available on the G'MIC sourceforge file server : https://sourceforge.net/projects/gmic/files/beta/


Tx for the improved command! I'll update G'mic. When I open terminal in the folder do I install it the normal way, i.e.:

.configure
make
make install

?


Top
 Post subject: Re: G'Mic montage from Command Line returning errors
PostPosted: Tue Mar 10, 2015 4:15 am  (#19) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
serche, there is no 'configure' in the G'MIC package. I just use a Makefile, so go to 'gmic/src/' and type 'make' and it should compile,
unless you have missing dependencies. Those dependencies can be found usually in your package manager.


Top
Post new topic Reply to topic  [ 19 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts How do you run GIMP from the command line?

1

No new posts Attachment(s) G'MIC> Pattern> Strip command line?

2

No new posts GEGL command line and layer modes?

2

No new posts Calling GIMP Plug-in From Command Line - on Windows

0

No new posts Attachment(s) G'MIC Montage

1



* Login  



Powered by phpBB3 © phpBB Group