Photo Mosaic with G'Mic

Hi guys,

I have question regarding the g’mic capabilities. I’m creating calendar with photos and I would like to achieve this photo mosaic effect [1].
I have around 400 photos I’d like to put into single image.

Can G’Mic help me ?

What I need to automate:
1st step: Find area of interest – faces, in photos and crop the photos to the same size, e.g. 100x100 pixels or something that will fit into final resolution depending on the number of photos (e.g. 4k photo: 3840 x 2160 and number of photos: ~400)

2nd step: tile the images intelligently so that e.g. average or median color of the photo match the final photo mosaic

That’s it I guess. So far I have experience with Arrays&Tiles → Montage, that is very nice filter. Is there some filter that can e.g. do the 2nd step?
I think the first step is too ambitious

[1] https://www.youtube.com/watch?v=51pDBwvZ0zk

Lukas

@Lukast_dev Welcome to the forum!

I agree. G’MIC doesn’t have face detection. However, there are packages that do; e.g., OpenCV and dlib, among others.

Uncertain but I can tell you that it is possible to make one.

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]