G'MIC exercises

Posting here as a reminder here to test the command later.

I haven’t tried yet, but from the error message, my guess is that your filter takes at least one parameter, and the GUI for your filter doesn’t provide a single one, hence the error.

Sorry, I accidentally omitted a sentence. I mentioned Hessian Norm because it works when it is running from gmic-community/include/afre.gmic (and has been since it was committed there) but not when I copy it to and run from user.gmic. So, it isn’t just my afre_cleantext test filter.

Have you a “minimal” version of your user.gmic that crashes and that we could look into ?

Ah, there are two separate problems. The no-parameter issue happens when I indent any or all of the lines with #@gui. Remove the indents and it works. However, if indenting messes up #@gui, why does Hessian Norm still show up as an entry in the plugin?

I don’t understand the second problem. Clean Text just crashes ATM. It is probably a silly mistake. I haven’t written plugin filters in a long time, sticking with CLI. That and I don’t sleep at all (should be doing it right now in my time zone) :blush:.

#@gmic user

#@gui Hessian Norm : fx_hnorm, fx_hnorm_preview(0)
#@gui : Strength = float(1,.5,1.5)
#@gui : Contrast = int(50,1,99)
#@gui : Invert = bool(0)
#@gui : sep = separator(), note = note("Filter by <i><a href="https://discuss.pixls.us/u/afre">afre</a></i>. Latest update: <i>2018-05-09</i>.")
  fx_hnorm :
    af_hnorm ^ $1
    c 0,$2%
    if $3 negate fi
    n 0,255

  af_hnorm:
    repeat $! l[$>]
      +hessian[0] xx +hessian[0] xy +hessian[0] xz +hessian[0] yy +hessian[0] yz hessian[0] zz
      sqr + s c + sqrt
    endl done

  fx_hnorm_preview :
  fx_hnorm $*

#@gui Clean Text : afre_cleantext, afre_cleantext_preview(0)
#@gui : Range = float(1,0,1)
#@gui : Black = int(70,0,100)
#@gui : White = int(90,0,100)
#@gui : sep = separator(), note = note("Filter by <i><a href="https://discuss.pixls.us/u/afre">afre</a></i>.
  afre_cleantext :
    retinex , norm n 0,1 f 1-gauss(i,$1) c $2%,$3% n 0,255 round

  afre_cleantext_preview :
    afre_cleantext $*

#@gmic _

There is an error is your note definition, it should be:

#@gui : sep = separator(), note = note("Filter by <i><a href="https://discuss.pixls.us/u/afre">afre</a></i>")

Apart from that, I see both filters running in the plug-in.

Thanks for pointing out the typo. As a follow up to #@gui, are you going to do something about it, or will just leave the filter writer to know not to indent them? At the very least, if indenting messes up the filter, make it so that the filter doesn’t show up at all in the plugin list.

I haven’t written a pull request before. I will try doing it for afre_cleantext and later afre_dehaze.

I’ll report that to the plug-in developer, and ask him what he can do about it.

1 Like

When I write

#@gui Clean Text : afre_cleantext, afre_cleantext_preview(0)
#@gui : Range = float(1,0,1)
#@gui : Black = int(70,0,100)
#@gui : White = int(90,0,100)
#@gui : sep = separator(), note = note("Filter by <i><a href="https://discuss.pixls.us/u/afre">afre</a></i>.")
afre_cleantext : skip ${1=1},${2=70},${3=90}
#@cli : Clean scanned text.
#@cli : 0<=range<=1,0<=black<=100,0<=white<=100
#@cli : Default: 1,70,90"
  retinex , norm n 0,1 f 1-gauss(i,$1) c $2%,$3% n 0,255 round

afre_cleantext_preview :
  afre_cleantext $*

When I do help, it says that afre_cleantext has no description. Is this a user.gmic thing? Or am I doing it wrong again?

By default, the command help doesn’t try to find command descriptions in something else than updateXXX.gmic.
When your command will be part of the update file, the help will appear.

Anyway to test how help will display, you can force it by:

$ gmic your_file.gmic help command

I tried and nothing shows.

gmic C:\Users\afre\AppData\Roaming\user.gmic help afre_cleantext

Well, I’ve never tried on Windows, it’s something I’ll check tomorrow if I have some time.

Awesome. I shall attempt a pull request in the meantime with what I have.

Isn’t there a line missing?

#@cli afre_cleantext :

Also, I do see help from my local .gmic definitions on linux at least (without any work)

Good call. Since we have been talking about it here. I will post the filter with all of the changes here for one last look before I make the pull request (procrastinating really :stuck_out_tongue:). Any more remarks or advice?

#@gui Clean Text : afre_cleantext, afre_cleantext_preview(0)
#@gui : Range = float(1,0,1)
#@gui : Black = int(70,0,100)
#@gui : White = int(90,0,100)
#@gui : sep = separator(), note = note("Filter by <a href="https://discuss.pixls.us/u/afre">afre</a>, 2019.")
#@cli : afre_cleantext :
#@cli : Clean scanned text.
#@cli : 0<=range<=1,0<=black<=100,0<=white<=100
#@cli : Default: 1,70,90"
afre_cleantext :
  skip ${1=1},${2=70},${3=90}
  check "$1>=0 && $2>=0 && $3>=0 && $1<=1 && $2<=100 && $3<=100"
  retinex , norm n 0,1 f 1-gauss(i,$1) c $2%,$3% n 0,255 round

afre_cleantext_preview :
  afre_cleantext $*

PS Oops, another crash. Another typo? Okay now.

Seems fine to me, I quite often polish up filters later on. Things like how many layers does it handle, does it handle opacity etc.
I’m sure you’ll do the pull request and think “oh. that’s all it is”. So don’t worry :slight_smile:

Three steps: Fork, edit (and commit), pull request. If you’re not familiar with “git”, perhaps stick with editing the file directly on github rather than cloning (after you forked).

I made the pull request a while ago. Wasn’t hard but required some sleuthing. I think I have used git a long time ago when building something and having to correct a disruptive bug. But that was a lot of stumbling in the endless void. :blush::laughing:

1 Like

Could the plugin not crash due to typos but indicate the error and its line instead?

Latest prerelease should already do that.

2 Likes