Foreground extraction (command line)

Hi, can someone help me with this tutorial? http://opensource.graphics/how-to-code-a-nice-user-guided-foreground-extraction-algorithm/

I’m using this command

.\gmic.exe IMG_7562.jpg 1.png --blur[0] 0.2% -gradient_norm[-1] -fill[-1] ‘1/(1+i^2)’ -watershed[1] [2] -reverse[-2,-1]

but I get an error:

[gmic]-0./ Start G’MIC interpreter.
[gmic]-0./ Input file ‘IMG_7562.jpg’ at position 0 (1 image 1056x813x1x3).
[gmic]-1./ Input file ‘1.png’ at position 1 (1 image 1056x813x1x3).
[gmic]-2./ Blur image [0] with standard deviation 0.2%, neumann boundary conditions and quasi-gaussian kernel.
[gmic]-3./ Compute gradient norm of images [0,1,2].
[gmic]-3./ Input copy of image [2] at position 3 (1 image 1056x813x1x1).
[gmic]-4./ Fill images [0,1,2,3] with values from image [3].
[gmic]-4./ Input file ‘1/(1+i^2)’ at position 4
[gmic]-4./ *** Error *** Unknown command or filename ‘1/(1+i^2)’.

Most likely, since that time the “-fill” command has changed, but how to use it now is not clear…
Example in this archive: Dropbox - File Deleted - Simplify your life

This looks like a Windows cmd.exe quoting error, that we just discussed here: Help with programming - #5 by David_Tschumperle

In the OP, the quotes around 1/(1+i^2) are “smart-quotes”, where the open and close quotes are different characters. For Windows, uses ordinary (non-smart) double-quotes, eg:

gmic toes.png toes.png --blur[0] 0.2% -gradient_norm[-1] -fill[-1] "1/(1+i^2)" -watershed[1] [2] -reverse[-2,-1]

It does not work me
I am interests idea to separate background and figure

What doesn’t work? The quoting? Another way is to escape the offending character like this
1/(1+i^2) → 1/(1+i^^2).

You mentioned this in several threads. Could you explain what you mean by that? Just wondering if you are asking about something specific rather than stating your interest in the topic.

I want to do something similar to this:

But without having to choose background and foreground

Unfortunately, both variants (double quotes and double ^^) doesn’t work.

Please paste the exact command you used, and the error messages.

This is my exit. I do not see changes

.\gmic.exe IMG_7562.jpg 1.png --blur[0] 0.2% -gradient_norm[-1] -fill[-1] ‘1/(1+i^^2)’ -watershed[1] [2] -reverse[-2,-1]
[gmic]-0./ Start G’MIC interpreter.
[gmic]-0./ Input file ‘IMG_7562.jpg’ at position 0 (1 image 1056x813x1x3).
[gmic]-1./ Input file ‘1.png’ at position 1 (1 image 1056x813x1x3).
[gmic]-2./ Blur image [0] with standard deviation 0.2%, neumann boundary conditions and quasi-gaussian kernel.
[gmic]-3./ Compute gradient norm of images [0,1,2].
[gmic]-3./ Input copy of image [2] at position 3 (1 image 1056x813x1x1).
[gmic]-4./ Fill images [0,1,2,3] with values from image [3].
[gmic]-4./ Input file ‘1/(1+i^^2)’ at position 4
[gmic]-4./ *** Error *** Unknown command or filename ‘1/(1+i^^2)’.

and

.\gmic.exe IMG_7562.jpg 1.png --blur[0] 0.2% -gradient_norm[-1] -fill[-1] “1/(1+i^2)” -watershed[1] [2] -reverse[-2,-1]
[gmic]-0./ Start G’MIC interpreter.
[gmic]-0./ Input file ‘IMG_7562.jpg’ at position 0 (1 image 1056x813x1x3).
[gmic]-1./ Input file ‘1.png’ at position 1 (1 image 1056x813x1x3).
[gmic]-2./ Blur image [0] with standard deviation 0.2%, neumann boundary conditions and quasi-gaussian kernel.
[gmic]-3./ Compute gradient norm of images [0,1,2].
[gmic]-3./ Input copy of image [2] at position 3 (1 image 1056x813x1x1).
[gmic]-4./ Fill images [0,1,2,3] with values from image [3].
[gmic]-4./ Input file ‘1/(1+i^2)’ at position 4
[gmic]-4./ *** Error *** Unknown command or filename ‘1/(1+i^2)’.

@Torvald read about quoting in Windows shell and look closely at what you’re using to quote. Well, @snibgo already explained it, but you’re still using the wrong quotes.

1 Like

I’m not sure if he’s using the wrong quotes. The forum software is converting ordinary quotes into “smart” quotes, where the open and close characters are different. I don’t know what can be done about that.

@Torvald See my example. You don’t have to quote if you don’t use any special characters or have any spaces. If you would like to use the caret either quote or escape but not both.

gmic sample tiger fill i^^1.5 cut 0,255
gmic sample tiger fill "i^1.5" cut 0,255

I I found out what the problem was. I used “Windows PowerShell”. When I tried the “Command line” - everything worked. I think the problem is how Windows PowerShell processes quotes. Thanks for the help.

1 Like