Photo Mosaic with G'Mic

http://www.complang.tuwien.ac.at/schani/metapixel/examples.html

1 Like

How did you do that?

@bazza Nice find. Metapixel is GPL too.

Well, it’s actually a program after all. I could have a little fun with this. Not very useful though, but I seen it in use.

Toyed with Metapixel in an Ubuntu VM a few years back. Still, no Windows compile unfortunately. :slight_smile:

yes is GPL and has excellent results.

@lylejk It is time to abandon window

I know the advice of abandoning Windows doesn’t go to me, but I would love to abandon Windows if it wasn’t for locked-in environment. I do use certain softwares that requires me to use Windows and it’s not just about Adobe or Affinity.

For all the other exist VirtualBox

Actually checking into a minimalist OS that can run other OS as containters. Did some research on Un-RAID, CoreOS and a few others for this. A co-worker actually uses Un-RAID but I’ve read a lot of negative comments about this program. My co-worker swears by Un-RAID and, except for the updates, it’s not stopped running on his setup for nearly a decade according to him. Still, my crutch has always been Windows; going to be hard for me to break that habit, @bazza. Still, if I can run Win10 in a container without any performance issues, then this would be ideal. I could run many different programs/OSs within containers to completely isolate such things from each other and the rest of my system. Anyway, that’s where I’m thinking about going with my next system, but if I do, I would like as many cores on the CPU as possible just in case I want to run a few OSs simultaneously. :slight_smile:

I have tried a number of things but none of them will ever work well on an aging low end machine.

Actually, I did found a partial step to a way of having photomosaic into G’MIC. I suppose we need a new command call array_fill to speed things up, and my technique with hardware stimulation can also apply here. Here’s what’s inside my head.

  1. First, have at least 3 image
  2. Apply generate 1x1x1x3 color image using the average of pictures except for the target image. That means 2 images will have 1x1x1x3 layer below them.
  3. Merge those as palette
  4. Apply the hardware stimulation technique into the first layer using the palette. For each square color, that will be filled with array_fill of those photo.
  5. You got your photomosiac.

I’m not sure how to describe it, but is it at least clear?

Show not tell. :stuck_out_tongue:

Well, almost done.

v=5
te={w<h?$v/w:$v/h}

to_a at[0] "get ia,0,0",{$te*w},{$te*h} r[^0] {$te*w},{$te*h},1,4,5 r[^0] {w#0},{h#0},1,4,0,2 split_opacity l[^0-1] repeat {$!/2} +get[{$>*2}] ia done +a[^0-{$!-1-$!/3}] x endl index[0] .,0,1 rm. r[^0-{$!-(($!+1)/3)}] {w#0},{h#0},1,{s},1

It looks like I rarely use lines these day. The next step is to erase mismatch between indexed image, and convert that to transparency mask which be applied to the smaller images. The opacity layers will be multiplied, and applied per tile images.

Also, saving this here for easier access to coding in the morning. Also, I’m using this equation to help me out.

y=2x+(x-1)

‘get’ is my latest cli command, and this makes the work a lot easier.

On the right, those colors are going where the photo tiles are going to be.

1 Like

And using patchmatch can not look for morphological resemblance (?)

I tried that, didn’t understand how it works, so I’ll just continue with this approach.

I only use this, but short pieces of the image:

gmic sample cat sample apples +patchmatch[0] [1],64,64,1,1,1 fx_posterize[2] 800,0,0,4,64,0,0,0,50,50 +warp[-2] [-1]

EDIT : Never mind, it didn’t work at all. :frowning:

I’ll try to find out another way, but this is definitely difficult to code.

I do not know if it’s useful, here’s an example of positioning and blending.

# example blending

# Gmicky 2w*1h
rm[0]
fx_gmicky 2
resize[-1] 200%

# variables
Color_Tolerance=10
Maximum_Number_of_Output_Layers=2
Minimal_Area_PourCent=8
Autocrop_Output_Layers=0
W_Origine={w}
H_Origine={h}
# 2 layers
quantize[-1] $Maximum_Number_of_Output_Layers
fx_split_colors[-1] $Color_Tolerance,$Maximum_Number_of_Output_Layers,$Minimal_Area_PourCent,$Autocrop_Output_Layers
to_rgba[-1,-2]
# Gmicky rgb
+fx_gmicky 0
to_rgb[-1]
# where you want to see Gmicky
expand_x[-1] {abs({$W_Origine-{w}})/2},0 
expand_y[-1] {abs({$H_Origine-{h}})/2},0
# blend alpha
blend[-1,-2] alpha

rv[-1,-2]

I did just found the solution, to creating photo-mosaic, but the result are atrocious, but it works nevertheless.

#@cli rep_lbchstatfunc_to_pal: (eq. to rep_layers_by_channel_statistical_function_to_palette)
rep_lbchstatfunc_to_pal: rep_layers_by_channel_statistical_function_to_palette $*
#@cli rep_layers_by_channel_statistical_function_to_palette: variable
#@cli: Converts layers to palette using statistical function by channels per layers into 1x1 tile, then append them.
rep_layers_by_channel_statistical_function_to_palette: to_rgb rep_bchstatfunc $1 a x

#copy and paste below into code filter in g'mic, and copy and paste above to somewhere where you can remove it when not needed#
v=5
te={w<h?$v/w:$v/h}
to_a
at[0] "rep_bchstatfunc ia,0",{$te*w},{$te*h} r[^0] {$te*w},{$te*h},1,4,5 r[^0] {w#0},{h#0},1,4,0,2 +rep_lbchstatfunc_to_pal[^0] ia split_opacity[^{$!-1}] index[0] .,0,1 rm. l[^0-1] repeat {$!/2} +rep_bchstatfunc[{$>*2}] ia,0 done endl l[^1-{($!-1)-($!-2)/3}] repeat {$!-1} l[0,{$>+1}] f. "i#0==i#1?255:0" to_gray. endl done endl repeat {($!-2)/3+1} l[{1+($>*2)},{($!-1)-($!-2)/3+$>}] / 255 f.. "i#0*i#1" * 255 endl done rm[^0-{($!-1)-($!-2)/3}] repeat {($!-2)/2} a[{$>+2},{$>+3}] c done blend[^0-1] alpha rv[0,2] rm. split_opacity[0] blend[^0] multiply a c

Using code, you can change the value of v. Works with any layer greater than 3 as 2 are at least needed minimum for the mosaic.

Here’s the atrocious result -

That’s due to the indexing technique. I may need to find out just how to get a better indexing for the purpose of generating the mosaic. Either that or I may have to add blending using the original [0] image. Or both.

EDIT: One more example, but this time, more passable. Had to add more images for the mosaic result.

EDIT: I may have to keep in mind about expand_x, and expand_y for future filters.

1 Like

Not quite what the OP was looking for, but nevertheless interesting. Reminds me of those Lego grid bases. Or a map of grid based video games.