Reptorian G'MIC Filters

I decided to make it the default to append digits. Now, new problem, I would like to multiply really big numbers, but Karutsuba’s approach is the only one I understand. Any ideas here?

At the moment, I’m thinking to do a multi-threaded approach. I multiply each digits per thread, then add them up.

Here’s subtraction which I managed to do correctly:


I may have discovered a bug with the G’MIC interpreter. I think something is wrong with v2s().

That being said, I fixed subtraction. I realized I made a huge oversight after more tests and fixed it. This also fix a long-standing bug with Mitchell Concatenation as the minuend/subtrahend were dependent on the first pixels rather than it actual concatenated result.

1 Like

Don’t want to derail the other thread:

So, my GUI filters are hard to use? I would like to know how to make them easier to use without losing flexibility.

For the code, there’s not much I can do to make it more readable other than naming layers. I don’t do that as stack-based thinking is enough for everything except where mandatory such as GUI filters that use $_persistent. I think it’s readable only after having long experience.

Hard to use may not be the right terms, but maybe hard to understand ? Like your Mitchell concatenation ? People like me would have to read a whole lot of wikipedia to just launch it. I?'m not even student level so maybe in time?

I just know i tried a few filters from your folder and 2 gave me an error, and a 3rd one didn’t seem to do anything. I’ ll check again, I’m on my phone right now and it’s just a pain to type this :laughing:

EDIT :

  • Axis Streak doesn’t seem to do anything?

  • Here is what i get when trying array_random_jumble_by_px :

[gmic_gimp_qt]./error/ When running command 'v 3 rep_array_random_jumble_by_px 5,5', this error occurred:
[gmic_gimp_qt]./error/ *** Error in ./rep_array_random_jumble_by_px/*foreach/ *** Command 'eval': [instance(153,102,1,2,0xfffec04a99c0,non-shared)] gmic<float32>::[gmic_math_parser] gmic<float32>::eval(): Function 'crop()': Second argument has invalid type 'vector2' (should be 'scalar'), in expression 'img_tile=crop(#0,I,0,0,tile_w,tile_h,1,s#0)'.
1 Like

That’s under work. You can see that in the recent posts. It’s broken now.

It does something with images that has varied alpha. That is what it made for. This thing can arguably be done with other channels too, and other color space. But, it’s pretty difficult to code that and the approach regarding handling alpha when using color channel has not been figured out. It’s a interesting idea for utilization of other channels.

I made these changes according to your findings:

Also, you should look at the fixed Array filter. I formatted it closer to your style such as 2 spaces, so that you can read it. Might be a little hard to digest, but easier than others because it use two spaces.

1 Like

@hover Remember that you wanted acrylic flowpaint render in G’MIC. I think with Domain Warping, we can have something like that.

image

This is another one of his work:


But, I’m not sure what this domain warping means. I will find out unless some one else already knows what this means. @grosgood might even have a idea close to this. I’m communicating with Guardian Gold in Discord to see if we can have something like this for G’MIC. Also, from the brief google search, seem like Domain Warping is very much known, so I may not even need to communicate with Guardian Gold to find out.

3 Likes

Here’s a good read: Inigo Quilez: domain warping - 2002.

I wouldn’t over-work the phrase “Domain Warping” into anything deep and mysterious that only a few cognoscenti know; creative play with the venerable warp command, and/or the various warp_* variants can get you tickets into this game. Say, start with Perlin noise for the base image. Twist, rotate, displace, as if mixing paint with (maybe a dynamically changing) warp displacement field, noise ⇒ warp ⇒ repeat, and you are “domain warping.” We’ve all done this; maybe we didn’t know at the time that the Chattering Classes had given it a fancy name.

Reminds me of this thread from a few years ago: Can G’MIC do those kind of textures?

1 Like

I’m getting somewhere with the recode of Mitchell Concatenation. New features though not much changes from original will come other than performance boost and slight more options. Nearly everything is possible with the old version with performance loss.


Multiplication is still super slow. What is shown is Base-500 Multiplication. Addition and Subtraction is over 10 times faster. The reason Multiplication is slow is because it is using grade-school multiplication. Don’t know how to implement Karutsuba or other multiplication method here.

2 Likes

G’MIC Doodling in the absence of discuss.pixls.us. In particular, an emulator for New York Abstract Expressionism ‘action painting.’ You can be the next Pollack! My contribution to the Mysteries of Domain Warping.

warpfun.gmic
#@cli warpfun : stircount>0,noisefunc="spikes",arg0>0,arg1>0,arg2>0
#@cli : Using selected images as bases, emulate New
#@cli : York Abstract Expressionism School's 'action
#@cli : painting', as exercised by Jackson Pollack et
#@cli : al. in the 1950's-60's. stircount: number of
#@cli : times to swirl around the mathematical space
#@cli : where the 'action painting' is
#@cli : embedded. Style: selects one from a number of
#@cli : warping patterns: checkbrd(0), perlin(1),
#@cli : plasma(2), (3)ripples and (4)spikes. Arg0 and
#@cli : arg1: warping dependent arguments. Arg2:
#@cli : Attenuation. Scales stirring strength from 0
#@cli : (zero - no warping takes place) to 1 (one -
#@cli : maximum warping). Pressing <ESC> whilst the
#@cli : monitor window is active to stop stirring and
#@cli : finish up with the image as is.
#@cli : $ -input myimage.jpg warpfun. 4,0.25
warpfun : -check "isnum(${3=0.5}) && $3>0  &&
                  isnum(${4=0})   && $4>=0 &&
                  isnum(${5=0})   && $5>=0"
          -skip "${1=32},${2=4}"
   scnt,nfunc,a0,a1,attn=${1-5}
   # Pick one of the noise makers cited in $pats,
   # either by numeric id or name. Put the name in
   # '$pat', if known, otherwise default $pat to
   # 'spikes'.
   pats=${-_noise_pats}
   N:=narg($pats)

   -local[] {
      # Specify noise maker by number?  Use that,
      # modulo the noise maker count, as an index
      # into the set of available noise
      # makers. Otherwise take specification as a
      # string and check if it matches the name of
      # one of the available noise makers. Default
      # to 'spikes' noise maker in the absence of a
      # match.
      -if isint($2)
         pat=${"arg0 ($2%"$N"),"$pats}
      -else
         pat,flag=$2,0
         -repeat $N {
             C=${"arg0 "$>","$pats}
             -if ['$C']==['$pat']
                flag=1
                -break
             -fi
          }
          -if !$flag
             pat=spikes
        -fi
      -fi
   }
   -foreach {
      nm={n}
      -name. current

      # One stir entails a number of discrete warps (lvls)
      # derived from the largest of image width or depth:
      # the base-2 log of this measure, rounded to the
      # nearest higher whole number, sets lvl and the
      # dimensions of the 2D "stirring space" a square
      # power-of-two dimensioned image. We embed the
      # currently selected image in this space,mirroring
      # content as a means to manage a mirror-based border
      # policy.
      lvls={round(log(max(w,h))/log(2),1,1)}
      ow,oh,dx,dy={w},{h},{2^$lvls-w},{2^$lvls-h}
      -expand_x[current] {$dx/2},3
      -expand_y[current] {$dy/2},3

      # Displacement fields, one each for a lvl-count
      # of scale-based warping images. A Haar analysis
      # of distance-to-salt-and-pepper noise spikes defines
      # the warping images. See Haar tutorial at gmic.eu.

      # Generate a noise pattern image from the selected
      # noise maker. Decompose that image into scale-specific
      # displacement vector fields, the number dependent on
      # the base-two logarithm of the current image's largest
      # dimension.
      100%,100%,1,1
      _$pat. $a0,$a1
      -normalize. 0,{255*$attn}
      -haar. $lvls
      -repeat $lvls
         -local[-1]
            -split[-1] yx,2
            -name ctr,ne,sw,diff
            -move[ctr] $!
         -done
      -done

      # Make warping images based on Haar sum-of-differences
      # and differences of sums. TODO: Differences of
      # differences (diff) could be put to some use, no?
      -remove[diff,ctr]
      -local[ne,sw]
         -repeat {($!/2)}
            -local[{2*$<},{2*$<+1}]
               -append c
            -done
         -done
      -done
      -resize[^current] {w#$current},{h#$current},{d#$current},2,5
      -foreach[^current] {
         lim={im#0}
         liM={iM#0}
         -orientation.
         -normalize {$lim},{$liM}
      }
      -mul[^current] {1.0/($scnt)}

      # Stir image through a gamut of scaled displacement fields.
      flag=0
      -do
         cs={$>+1}
         -repeat {$!-1}
            cw={$>+1}
            -warp[current] [{$<+1}],1,2,3
            +crop[current] {$dx/2},{$dy/2},{$ow+($dx/2)-1},{$oh+($dy/2)-1}
            -name. preview
            -text_outline[preview] "Warp\ "$cw"\ of\ "{$!-2}";\ Stir\ number:\ "$cs"\ of\ "$scnt"\ Attenuation:\ "$attn,3%,85%,3%,1,1,255,240,200
            -window[preview]
            -wait 250
            -remove[preview]
            -if {*,ESC}
               flag=1
               -break
            -fi
         -done
      -while $><$scnt-1" && "$flag==0
      -keep[current]
      -crop[current] {$dx/2},{$dy/2},{$ow+($dx/2)-1},{$oh+($dy/2)-1}
      -normalize[current] 0,255
      -name[current] $nm
   }

# Noise functions: generate sets of displacement fields
# from images painted by these functions. Each should return
# a one channel image with channel values ranging from 0-255.

_noise_pats :
-status checkbrd,perlin,plasma,ripples,spikes

_checkbrd : -check "isnum(${1=16}) && isnum(${2=8})"
   foreach {
       -fill. xor(x,y)%$1<$2?1:0
       -distance. 1,2
   }

_perlin : -check "isnum(${1=16}) && isnum(${2=16})"
   foreach {
       -noise_perlin. {$1},{$2}
   }

_plasma : -check "isnum(${1=16}) && isnum(${2=16})"
   foreach {
       -plasma. {0.01*$1},{0.01*$2},{($1*$2)%8}
       -abs.
   }

_ripples :  -check "isnum(${1=16})" -skip ${2=16}
   foreach {
       -input {$1},1,1,3,[u(w#-1),u(h#-1),u>=0.5?-1:1]
       -rbf. {w#-2},{h#-2}
       -abs.
       -mod {1/$2}
       -keep.
   }

_spikes : -check "isnum(${1=0.5}) && isnum(${2=0})"
       -noise. {0.0001*$1},2
       -abs.
       -normalize. 0,1
       -if $2>0
          100%,100%,1,1
          -plasma. 0.5,0.5,{$2%8}
          -normalize. 0,{1+$2}
          -distance.. 1,[-1],0
          -remove.
       -else
          -distance. 1,2
       -fi

A Haar wavelet decomposition of a noise field furnishes the Domain Warping mystique.
stircount: number of times to swirl around the mathematical space where the ‘action painting’ is embedded. Style: selects one from a number of warping patterns: checkbrd (0), perlin (1), plasma (2), ripples (3) and spikes (4); choose by name or number. Arg0 and arg1 are warping dependent arguments. See examples for guidance. Arg2: Attenuates stirring strength. Unity is full strength; such decreases on an approach to Zero. See examples for guidance. As it proceeds, it throws up an interactive window showing progress; hit <ESC> in the interactive window if an intermediary result strikes your fancy. That stops further warpage.

gmic run '-m warpfun.gmic sample portrait4,512 warpfun. 4,4,13,5,0.02 n. 0,255'

warpfun_spikestoo

gmic run '-m warpfun.gmic 512,512,1,1,255*x/(w-1) map jet warpfun. 3,spikes,135,5,0.05 n. 0,255'

warpfun_spikes

gmic run '-m warpfun.gmic sp cat,512 warpfun. 3,ripples,50,6,0.05'

warpfun_ripples

gmic run '-m warpfun.gmic sp flower,512 warpfun. 6,plasma,1,9,0.05 n. 0,255'

warpfun_plasma

gmic run '-m warpfun.gmic 512,512,1,1,255*y/(h-1) map rainbow warpfun. 2,checkbrd,71,3,0.2 n. 0,255'

warpfun_checkbrd

gmic run '-m warpfun.gmic 512,512,1,1,255*y/(h-1) map hocuspocus warpfun. 5,perlin,200,20,0.02 n. 0,255'

warpfun_perlin

Have fun!

5 Likes

Not much update other than Mitchell Concatenation is still on work and is likely to be done tomorrow. In addition, I repaired rep_r_combinations (slight slower code than earlier implementation (.04 s loss when comparing 3x10^6 combinations), but easier to understand and translate).

I made a new command which allows you to sort images given images name order. There’s a example you can run:

$ sample portrait2,duck,fruits,portrait1,portrait2,duck,duck,fruits rep_sort_images_by_images_name_order duck,portrait2,fruits,portrait1 echo ${lof\ n} rm
[gmic]-0./ Start G'MIC interpreter (v.3.2.7).
[gmic]-1./ Input sample image 'portrait2' (1 image 800x800x1x3).
[gmic]-2./ Input sample image 'duck' (1 image 640x480x1x3).
[gmic]-3./ Input sample image 'fruits' (1 image 600x400x1x3).
[gmic]-4./ Input sample image 'portrait1' (1 image 800x800x1x3).
[gmic]-5./ Input sample image 'portrait2' (1 image 800x800x1x3).
[gmic]-6./ Input sample image 'duck' (1 image 640x480x1x3).
[gmic]-7./ Input sample image 'duck' (1 image 640x480x1x3).
[gmic]-8./ Input sample image 'fruits' (1 image 600x400x1x3).
duck,duck,duck,portrait2,portrait2,fruits,fruits,portrait1
[gmic]-8./ Remove images [0,1,2,(...),5,6,7] (0 images left).
[gmic]-0./ End G'MIC interpreter.

You can remove echo ${lof\ n} rm in order to display the result in images form.

1 Like

Cool, can it be used with wildcards or maybe incomplete names?

No to both. You have to input the exact name. And there are limitations of not accepting space.

@David_Tschumperle Any idea to address those limitations?

Would be nice to use part of name to sort all portraits together for example.
But anyway, if I remember well the command name names selections and not images themselves, right? At least that’s how I see it. That’s probably why you can name multiple images as “duck”, otherwise it would just lead to confusion :
gmic repeat 5 sp done name[0,2] duck negate[duck]

I’ll have to remember to use this in my scripts though haha.

Spaces and computing don’t go too well together anyway… Reminds me some headaches when i wrote a bash script to “link (from a NAS),read metadata,equalize, convert to opus,rename,rearrange folders,replaygain albums,lftp to phone” my FLAC files to use in guayadeque. And all using parallel. Spaces and single quotes in filenames are still breaking the thing sometimes.

I think I found my own answer. To treat image names as a vector of Unicode value and that requires to concatenate them somehow. That way, one can use space inside arguments.

Here’s the code:

#@cli rep_str2varj:
#@cli : Convert string to a string that represents a string that can be joined with a variable name.
rep_str2varj:
({'{'"$*"'}'})
replace[-1] {_','},{_'_'}
status _{t}
rm.

And example use:

C:\Windows\System32>gmic rep_str2varj \"Hi there, this is Reptorian.\" echo ${}
[gmic]-0./ Start G'MIC interpreter (v.3.2.7).
_72_105_32_116_104_101_114_101_44_32_116_104_105_115_32_105_115_32_82_101_112_116_111_114_105_97_110_46
[gmic]-0./ End G'MIC interpreter

However, the name sucks and so do the description.

EDIT: Nah, this doesn’t seem to work well with space case. I have to debug that. This is the full code for now:

#@cli rep_sort_images_by_images_name_order: name_a,name_b
#@cli Sort images accordingly to images name. Duplicates images name are not accepted!
#@cli : $ sample portrait2,duck,fruits,portrait1,portrait2,duck,duck,fruits rep_sort_images_by_images_name_order duck,portrait2,fruits,portrait1
rep_sort_images_by_images_name_order:
if $!<2 return fi

set_of_names_count,relative_pos=$!,0
$=arg

repeat $! {
 id=${rep_str2varj\ {'{$>,n}'}}
 if narg(${img_name_id_$id})
  img_name_id_$id+=1
  set_of_names_count-=1
 else 
  img_name_id_$id=0
 fi
}

repeat $set_of_names_count {
 id=${rep_str2varj\ {'{$>,n}'}}
 img_id=${img_name_id_$id}
 if narg($img_id)
  move[${arg{$>+1}}] {$>+$relative_pos}
  relative_pos+=$img_id
 else error name_not_found
 fi
}

#@cli rep_str2varj:
#@cli : Convert string to a string that represents a string that can be joined with a variable name.
rep_str2varj:
({'$*'})
replace[-1] {_','},{_'_'}
status _{t}
rm.

As long as you wrap the string appropriately, I recall the spaces transferring. I have a bad memory, but it has to do with a mixture of bracketing and quoting. Perhaps, it won’t work with names. Again, I don’t quite remember.

Well, David pointed to named. A command I have used before, but didn’t know specifically what it does. I fixed it, and this is the current command:

#@cli rep_sort_images_by_images_name_order: name_a,name_b
#@cli Sort images accordingly to images name. Duplicates images name are not accepted!
#@cli : $ sample portrait2,duck,fruits,portrait1,portrait2,duck,duck,fruits rep_sort_images_by_images_name_order duck,portrait2,fruits,portrait1
rep_sort_images_by_images_name_order:
img_moved=0
$=arg

for $img_moved<$! {
 named[$img_moved--1] 0,${arg{$>+1}}
 t_arg:=narg(${})
 
 if $t_arg
  move[${}] $img_moved
  img_moved+=$t_arg
 else error missing_image_name
 fi
}

Another new command, and it’s short enough to share the whole code:

#@cli rep_python_insert_integer_value:
#@cli : Allows user to insert integer values from the cli interface. Then, return the integer value.
rep_python_insert_integer_value: 
exec 1,"python -c \"import sys; sys.exit(int(input('\\n[gmic][python]-"$^"./ Input Integer Value: ')))\""

You can easily guess how this works. But, this is all I can do with mixing two languages without resorting to socket.

D:\Programs\G'MIC\gmic-community>gmic rep_python_insert_integer_value echo the_output_is_${}
[gmic]-0./ Start G'MIC interpreter (v.3.2.7).
[gmic][python]-0./ Input Integer Value: 175601

the_output_is_175601
[gmic]-0./ End G'MIC interpreter.

Which brings me to brainfuck interpreter I did. I only did this because there’s no equilavent of std::cin in G’MIC. Here - Brainfuck Code interpreter written in G'MIC

Also, realized that there’s a limitation that dependent on OS.

More progress on the upgrade to Mitchell Concatenation. I managed to get more modes working, and that means that this filter has more possibility than before, but only to the scope of said filter.


Current Code - Current Code for Mitchell Concatenation - Pastebin.com

You can tell that it’s pretty complicated.

1 Like

Ok, more updates. It looks like the base generation of Mitchell Concatenation is done. The next thing is some few code updates to handle how the images are to be created beyond just what is Mitchell Concatenation.



2 Likes

Now, I’m releasing a beta version of the rep_mitchell_concatenation. To use it, paste into user.gmic and use new_rep_mitchell_concatenation.

Code so far is 1706 lines of code. :woozy_face: And I still have to finish how to process newly created images or finalization. The generation of the Mitchell Concatenation is done.

And sample CLI interface code:

$ 2000,2000 pal {expr('int(u(0,380,1,0))',2)} new_rep_mitchell_concatenation[0] 1,15,add,1,20,sub,20,[1],[2],cubic,star,95%,10,0,2

If you’re using second or third allowed argument, you need to have at least one [palette]. And if you’re using second, the options to replace [palette] are 0 or 1. If you’re using third, the options to replace [palette] are -2,-1,1 and negative will only use either first or second set of arguments before form_pixel size.

Easiest case of Mitchell Concatenation is this:

$ new_rep_mitchell_concatenation 1,10,add

You can even verify the result by assuming the very bottom is 1. And going up to 9 and do 987654321+123456789=1111…0 and then at n=10, it would be 12345678910+10987654321. And you finally learn what is Mitchell Concatenation is. If you change the base, and in case of base 16, it’d be like 123456789abcdef10+10fedcba987654321, and it still works at base 500+ because 19 is a single digit in base 500. Honestly, this would make a good numberphile video.