It is currently Sat Aug 08, 2026 3:17 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 18 posts ] 
Author Message
 Post subject: CImg calls behind the "solidify" example
PostPosted: Mon Sep 02, 2013 10:31 am  (#1) 
Offline
GimpChat Member

Joined: Sep 02, 2013
Posts: 9
Hi everyone,
I spent a few hours playing with G'MIC online (and I luv it :gimp ) and I was wondering which c++ call(s) to the CImg subroutine are behind the "solidify linear" preset.
Thanks a lot for your help!


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: CImg calls behind the "solidify" example
PostPosted: Mon Sep 02, 2013 10:38 am  (#2) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
G'MIC defines its own script language, and the 'solidify_linear' command has been created as a G'MIC script.
So, it doesn't call a single CImg method, but a lot of them.
The G'MIC source code of this command is available there : http://pastebin.com/d8SqQf6c
As you can see (if you understand the G'MIC language), this uses iterative dilations to perform the effect.

G'MIC has been primarily created to shorten the coding of simple IP algorithms (like this one). Most of the G'MIC commands are in fact written like this.


Top
 Post subject: Re: CImg calls behind the "solidify" example
PostPosted: Mon Sep 02, 2013 10:58 am  (#3) 
Offline
GimpChat Member

Joined: Sep 02, 2013
Posts: 9
I was afraid you would give me that answer :)
So it is up to me to translate this to C, right?
I suppose the pde_TschumperleDeriche2d.cpp sample is a bit old now and has nothing in common with Solidify linear?


Top
 Post subject: Re: CImg calls behind the "solidify" example
PostPosted: Mon Sep 02, 2013 11:42 am  (#4) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
Exactly. Sorry about that!
The pde_TschumperleDeriche2d.cpp is indeed a bit old and has nothing to do with Solidify linear (but has some links with the '-smooth' command of G'MIC by the way).

Note that I've started G'MIC because I was a bit tired of having to write small C++ codes like I would have to do for coding 'Solidify linear'. Instead, I created a script language that makes it easier (for me at least) to write such things in a quick way. And it is reusable for anyone, unlike the multitude of small C++ code I had in my 'To sort/' folder :)


Top
 Post subject: Re: CImg calls behind the "solidify" example
PostPosted: Tue Sep 03, 2013 2:46 am  (#5) 
Offline
GimpChat Member

Joined: Sep 02, 2013
Posts: 9
Is there any chance you still have the c++ solidify code somewhere in that folder :)


Top
 Post subject: Re: CImg calls behind the "solidify" example
PostPosted: Tue Sep 03, 2013 10:44 am  (#6) 
Offline
GimpChat Member
User avatar

Joined: Jan 03, 2011
Posts: 1656
I never wrote this feature in c++ before :-)


Top
 Post subject: Re: CImg calls behind the "solidify" example
PostPosted: Tue Sep 03, 2013 5:00 pm  (#7) 
Offline
GimpChat Member

Joined: Sep 02, 2013
Posts: 9
My god, I'm trying to decipher the script, I think translating chinese would be easier.
I'm using gmic help but I'm blocked even on the simplest lines, I feel stupid :(

bool solidify_linear(imageList<color>, float sigma=1.5f, float dsigma=2.0f, float precision=0.5f)
{
    if( sigma < 1 || dsigma < 1 || precision < 0 || precision > 1 )
        return false;
       
    // echo some stuff
    // decrease verbose level
    for (int i=0; i<imageList.size(); i++)
    {
        // local block
       
        // Split color and opacity parts of selected images.
        split_opacity(); // but where is the result stored???
       
        if( i > 1 ) //why do we wait for 3rd image??
        {
           // construct boolean image from imageList[i-1] with a threshold of 50%
           tmpImg<bool> = thresh(imageList[i-1], 50%);
           tmpImg = tmpImg * imageList[i-2];

            do {
               int v = round(3*sigma);
               int N = min(33, max(3, v+1-(v%2)));
               // You killed me with that one:
               // $N,$N -=[-1] 1,50%,50% -distance[-1] 1 -*[-1] {-1/$sigma^2} -exp[-1] -normalize_sum[-1]
               // To be continued
            } while (!im) // what is im ??
        }
   
    }
   
    // increase verbose level

}


Top
 Post subject: Re: CImg calls behind the "solidify" example
PostPosted: Wed Sep 04, 2013 12:50 pm  (#8) 
Offline
GimpChat Member

Joined: Sep 02, 2013
Posts: 9
I read your "Why another script language ?" blog post and I understood that translating from G'IMC to C is the last thing you would do on earth.
While I totally respect the fact that you want to target non-developer users, I just don't understand the logic that lead you to write "another (cryptic) script language".
IMHO non-developer users just run away when they see things like "$N,$N -=[-1] 1,50%,50% -distance[-1] 1 -*[-1] {-1/$sigma^2} -exp[-1] -normalize_sum[-1]"
I can't speak for them, but I would expect them to be more familiar with things that look like pseudo-code or are even closer to natural language.

To get back to my topic, would you recommend me a way to answer my initial question by myself? (like look at the parser with the debugger, or increase verbosity of G'IMC?)


Top
 Post subject: Re: CImg calls behind the "solidify" example
PostPosted: Wed Sep 04, 2013 6:56 pm  (#9) 
Offline
GimpChat Member

Joined: Feb 13, 2013
Posts: 86
neFAST wrote:
I can't speak for them, but I would expect them to be more familiar with things that look like pseudo-code or are even closer to natural language.
)


I'm a non-developer, and I found that writing G'MIC scripts is pretty easy especially with the GIMP plugin, because of means I don't have to touch the command line. It was a bit tricky to get started but, once I was over that bump I've managed to write some very complicated scripts.


Top
 Post subject: Re: CImg calls behind the "solidify" example
PostPosted: Wed Sep 04, 2013 7:50 pm  (#10) 
Offline
GimpChat Member

Joined: Apr 12, 2010
Posts: 5870
Ditto
My mind settings are very far from that of a developer , i am artist ,i am quite messy and even worse for try to even attempt to write code i make often typo and i tend to forgot to close parenthesys

yet i could manage to do some script for gmic , it was quite a effort but for sure i would not be able to do the same in C, python or script fu

It is true that Ronounours when code his filters and things tend to use the most compact language possible using always abbreviated form of commands (I.E. "-n" instead then "-negative") and very seldom insert comment lines, that make the code maybe more efficient but surely harder to decipher .

But on the other hand the GMIC language IS simple and the more important the documentation is complete , clear , and well exposed

But i can't say nothing about Clmg

_________________
My 3D Gallery on Deviantart http://photocomix2.deviantart.com/
Main gallery http://www.flickriver.com/photos/photocomix-mandala/
Mandala and simmetry http://www.flickriver.com/photos/photocomix_mandala/

Image

Mrs Wilbress


Top
 Post subject: Re: CImg calls behind the "solidify" example
PostPosted: Thu Sep 05, 2013 2:18 am  (#11) 
Offline
GimpChat Member

Joined: Sep 02, 2013
Posts: 9
Dear Iain and PhotoComix, thank you for you insights.
So if gmic is simple and easy for you, could you help me translate this script to plain English? (like "dilate image #1 and multiply it with image #2, loop until this parameter is null, etc.)
-v - -repeat @# -l[$>]
    -split_opacity
    -if {@#>1}
      -ge[-1] 50% -*[-2] [-1]
      sigma=$1 -do
        N={v=round(3*$sigma);min(33,max(3,v+1-(v%2)))}
        $N,$N -=[-1] 1,50%,50% -distance[-1] 1 -*[-1] {-1/$sigma^2} -exp[-1] -normalize_sum[-1]
        --convolve[-3,-2] [-1] -rm[-3]
        -max[-1] 1e-5 -/[-2,-1]
        --dilate[-2] {v=round((1/3-$N/6)*$3+$N/2);max(3,v+1-(v%2))}
        --[-3] [-1] -*[-2] [-3] -rm[-3]
        --[-3,-2]
        sigma={$sigma*$2}
      -while {!im}
     -rm[-1]
   -endif
-endl -done -v +


Top
 Post subject: Re: CImg calls behind the "solidify" example
PostPosted: Thu Sep 05, 2013 2:58 am  (#12) 
Offline
GimpChat Member

Joined: Feb 13, 2013
Posts: 86
Here's my best explanation. I had to look some stuff up from the reference http://gmic.sourceforge.net/reference.shtml


-verbose - -repeat @# -local[$>] ## set log messages to verbose, repeat for the number of images in the list, start local processing on image with the same number as the current repeat/done loop

-split_opacity ## split image to one non-alpha and one image represtning the alpha channel. The image list should contian two images.

-if {@#>1} ## if the number of image sn the list is greater than 1 then

-ge[-1] 50% ## apply a threshold at greater than or equal to 50% value on image [-1] (the last imeg in the image list which was the alpha chanel)

-*[-2] [-1] ## multiply the second to last image [-2] by the last image [-1]

sigma=$1 ## set varible 'sigma' to the first user input value

-do
N={v=round(3*$sigma);min(33,max(3,v+1-(v%2)))} ## set variable 'N' to the result of that math

$N,$N ## create a new image at the end of he image list that is NxN diminsions with defualt vaules of 1 channel ans pixels vaules of zero

-=[-1] 1,50%,50% # set the centre pixel value to 1


-distance[-1] 1 ## Compute the unsigned distance function to specified isovalue or coordinates.


-*[-1] {-1/$sigma^2} # multiply the last image in the list buy {-1/$sigma^2}


-exp[-1] # Compute the pointwise exponential of the last image [-1].

-normalize_sum[-1] # Normalize selected images with a unitary sum.

--convolve[-3,-2] [-1] ## convolve the 3rd to last and the 2nd to last images in the list by the last image in the list, and create a new image with the result at the end of the image list


-rm[-3] # remove the third to last image

-max[-1] 1e-5 # find the maximum value in the last image in the list comapre to 1e-5

-/[-2,-1] # divide the second to last image and the last image and keep only the result


--dilate[-2] {v=round((1/3-$N/6)*$3+$N/2);max(3,v+1-(v%2))}

# dilate the second to last image in the list with radius={v=round((1/3-$N/6)*$3+$N/2);max(3,v+1-(v%2))}


--[-3] [-1] # subtract image[-1] from image[-3]

-*[-2] [-3] # multiply image[-2] by image[-3]

-rm[-3] # remove image[-3]
--[-3,-2] # subtract images and only keep the result
sigma={$sigma*$2} # change vaule of 'sigma' to sigma* user input number 2
-while {!im} # end of do-while loop, 'im' means lowest value of an image but I'm not sure exactly what {!im} means
-rm[-1] ## remove the last image in the image list
-endif
-endl # end local processing
-done # end of repeat-done loop
-v +


Top
 Post subject: Re: CImg calls behind the "solidify" example
PostPosted: Thu Sep 05, 2013 2:31 pm  (#13) 
Offline
GimpChat Member

Joined: Sep 02, 2013
Posts: 9
Thanks a lot for your help.
Can you confirm that loading a color (rgba) image results in 2 (rgb+a) or 4 (r+g+b+a) images ?


Top
 Post subject: Re: CImg calls behind the "solidify" example
PostPosted: Thu Sep 05, 2013 3:26 pm  (#14) 
Offline
GimpChat Member

Joined: Apr 12, 2010
Posts: 5870
temporary ,during gmic inner process: the final result is one image again

_________________
My 3D Gallery on Deviantart http://photocomix2.deviantart.com/
Main gallery http://www.flickriver.com/photos/photocomix-mandala/
Mandala and simmetry http://www.flickriver.com/photos/photocomix_mandala/

Image

Mrs Wilbress


Top
 Post subject: Re: CImg calls behind the "solidify" example
PostPosted: Thu Sep 05, 2013 4:14 pm  (#15) 
Offline
GimpChat Member

Joined: Sep 02, 2013
Posts: 9
ok but I is it 2 or 4? I have alpha in [-1], what is in [-2]?


Top
 Post subject: Re: CImg calls behind the "solidify" example
PostPosted: Thu Sep 05, 2013 4:38 pm  (#16) 
Offline
GimpChat Member

Joined: Apr 12, 2010
Posts: 5870
maybe is the word "images" to confound here

"Alpha" contain info on transparency , users usually want transparent area be protected as if were unselected.

So the Alpha is just split and stored, you may consider as a back up , the rest is processed
and at the end is added again Alpha , and so all info on transparency

_________________
My 3D Gallery on Deviantart http://photocomix2.deviantart.com/
Main gallery http://www.flickriver.com/photos/photocomix-mandala/
Mandala and simmetry http://www.flickriver.com/photos/photocomix_mandala/

Image

Mrs Wilbress


Top
 Post subject: Re: CImg calls behind the "solidify" example
PostPosted: Thu Sep 05, 2013 5:21 pm  (#17) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
neFAST wrote:
ok but I is it 2 or 4? I have alpha in [-1], what is in [-2]?

[-2] contains the RGB components of the layer. It would be the same as in GIMP if you had a layer with an alpha channel and added a layermask using the "Transfer Layer's Alpha Channel" option: the layermask would contain a grayscale copy of the alpha channel while the layer itself would be filled with fully-opaque pixels in the original colors.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Top
 Post subject: Re: CImg calls behind the "solidify" example
PostPosted: Fri Sep 06, 2013 4:16 am  (#18) 
Offline
GimpChat Member

Joined: Sep 02, 2013
Posts: 9
Thank you for your help.


Top
Post new topic Reply to topic  [ 18 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group