Sharpen [Deblur] high-level description?

Hi,
I’m trying to understand how the “Details → Sharpen [Deblur]” filter works (specifically, the version with “mean curvature” regularization, if that makes any difference), but my knowledge of the G’MIC language is essentially zero. Is there anyone that can provide a high-level description of its steps?
Thanks in advance!

Have you come across Mean curvature - Wikipedia? Would it help give you a better idea on the aim of the filter?

Looks like the regulation is based on:

#@cli iee
#@cli : Compute gradient-orthogonal-directed 2nd derivative of image(s).
#@cli : $ image.jpg iee
iee :
  e[^-1] "Compute gradient-orthogonal-directed 2nd derivative of image$?."
  foreach {
    if d==1
      +g xy,0 hessian... xxxyyy      # ixx ixy iyy ix iy
      *... .. *[-4] . *[-4] -2       # ixx -2iyixy ixiyy ix iy
      +[-4,-3] *... ..               # ixx -2ixiyixy+ix^2iyy ix iy
      sqr[-2,-1] *[-4] . +[-4,-3]    # iy^2ixx-2ixiyixy+ix^2iyy ix^2 iy^2
      +[-2,-1] +. 1e-8 /             # (iy^2ixx+2ixiyixy+ix^2iyy)/(ix^2+iy^2)
    else
      +inn laplacian.. -
    fi
  }

Hi @afre, thanks a lot for the reply! I’m assuming the comments in the pseudocode are supposed to be explanations, but I must admit I don’t know how to read them, sorry: they are probably self-explanatory for someone familiar with the gmic interpreter, but as an outsider I’m having a very hard time following what is going on… To clarify, I’m not asking for low-level explanations, but rather for a high-level description of the main steps of the algorithm. Once I have that clear, I can try figuring out the details myself (with the help of wikipedia among other things)

TIA

I know. It would be great if you could clarify the high-levelness you are expecting with perhaps an example. Let me know what you do not understand about the code specifically. Note that I will not be the best person to assist with the implementation stuff, but hopefully I have given and will give you more to go by in your own investigation.

The command deblur that is the core component of the filter Details / Sharpen [Deblur] mentions the “regularized Jansson-Van Cittert algorithm”.
I found a description of this algorithm in this paper (in section 4.3):

https://opg.optica.org/directpdfaccess/0ee9f914-4c2a-4e6b-988a92d32378bd9c_416272/oe-27-16-23049.pdf?da=1&id=416272&seq=0&mobile=no

It is basically an iterative algorithm for image deconvolution.
The regularization term can be chosen among classical ones (Tickhonov: isotropic regularization, or meancurv and TV which are two anisotropic regularization terms).

1 Like

Well, I’m having a hard time reading the code, that’s it. So maybe instead of something like:

[0] +b. $1 -[-2,-1]

maybe something like:

blurred = blur(input, arg1)
res = input - blurred

(assuming I got it right)

Anyway it’s really not urgent and answers like “please go RTFM” are totally acceptable… :slight_smile:

1 Like

Let’s break this down:

[0] +b. $1 -[-2,-1]

Broken down:

[0] # 1. Create a copy of Image #0
+b. $1 # 2. As the period after denote, that means last image. two period means second image. There's a plus here too. That means to make a copy. So, this means make a new image representing a blurred image of the last image on the sack with radius of $1.
-[-2,-1] #3. Subtract second last image by first last image, and remove the last selected image. You can look at this as two layers flattened with a subtract blend mode.

So, I think you got it almost correct.

1 Like

Sorry @agriggio, I misunderstood your original question, which was to decipher the G’MIC code in human readable language or simple pseudocode. Thanks @Reptorian for answering.

This is never (or rarely) an issue. We welcome and honour every question. Cheers.

Related, is there any way to debug the current image stack? I.e. figure out what e.g. [-4] refers to (For example by giving names to images or dumping their id or something… I don’t know)?

If you’re running G’MIC cli, then you could add display next to place of interest in the code, and then make your notes there. I often do this when I’m making codes in G’MIC as I like to know what’s going on.

name and print would be the go-tos in CLI. name allows you to name images and print to output basic image information. display also does print in addition to displaying the images in the image list.

Tip 1: you can name, print and display at any point of the command. With display, the command pauses and then continues only after you close the window.

Tip 2: verbose allows you to control the verbosity of the command line, so you can look into the finer details of the sub-commands.

2 Likes

Hi again,

I think I figured out what the code does, but I’m still having troubles in mapping it to the description in the linked paper… Can you maybe elaborate a little bit how regularization is supposed to work? I couldn’t see this described in the paper above (and in general I couldn’t find anything about regularized jansson-van crittert; I could find other applications of regularization in deconvolution, but for different algorithms). Also, what is called “mean curvature” in the filter GUI seems to be a bit different from the definitions I found, can you comment on that?
Sorry if the questions are too naive…