Excellent paper. Kudos.
Perhaps a quick cheatsheet on G’MIC compositing can serve many of your image blending purposes, such as making a foreground knock-out mask to modify a so-called middle ground image, one that already has a transparency channel so that it, in turn, composites onto a background image. The general scheme here is: “select from two sources based on a third selection function, implemented by a grayscale mask”
For G’MIC, blending between two images at ratios taken from a third, masking, image is the providence of image (shortcut j
) and blend.
image
is a so-called “built-in” (C++ implemented within the interpreter), is fast, but a very basic, compositor between a positional “sprite” (thought of as a “floating image”) and a base image, stuck on the ground with the sprite “hovering” over it, and a grayscale “mask” that punches holes in the sprite so that the base image shows through. More formally, the mask serves as a basic compositing function that “selects A, B, or a ratio of the two”.
blend
is a more full-featured compositing engine operating on image pairs blended through a wide variety of compositing functions, many familiar (Porter-Duff) and some less so. blend
started life as an emulator of GIMP blending functions (in turn based on Photoshop composition functions); it still follows that model but has some blending functions that are not part of GIMP. Here is an enumeration of the G’MIC Blending modes.
This is a (really long!) one-liner masking demo that can be middle-mouse-button-swiped (or Windows cut-and-paste) into a shell (but beware the shell ):
gmic \
-input 512,512,1,3 \
[0]x1 \
-name[-2] pattern \
-name[-1] gradient \
-input 100%,100%,100%,1 \
-name. mask \
-fill[pattern] "xor(x,y)%17<9?[114,159,207]:[250,230,80]" \
-fill[gradient] "lerp([5,20,50],[10,50,150],y/(w-1))" \
-polygon[mask] 5,140,150,400,175,310,440,150,420,105,350,1,1,1,1 \
-blur[mask] 5% \
-image[gradient] [pattern],0,0,0,0,1,[mask] \
-keep[gradient] \
-output[gradient] /dev/shm/composite.jpg,80
If the swipe into a command shell works, you should get a log print-out of what G’MIC is doing:
[gmic]./ Start G'MIC interpreter (v.3.5.3).
[gmic]./ Input black image at position 0 (1 image 512x512x1x3).
[gmic]./ Input copy of image [0] at position 1 (1 image 512x512x1x3).
[gmic]./ Set name of image [0] to 'pattern'.
[gmic]./ Set name of image [1] to 'gradient'.
[gmic]./ Input black image at position 2 (1 image 512x512x1x1).
[gmic]./ Set name of image [2] to 'mask'.
[gmic]./ Fill image [0] with expression 'xor(x,y)%17<9?[114,159,207]:[250,230,80]'.
[gmic]./ Fill image [1] with expression 'lerp([5,20,50],[10,50,150],y/(w-1))'.
[gmic]./ Draw 5-vertices filled polygon on image [2], with opacity 1 and color (1,1,1).
[gmic]./ Blur image [2] with standard deviation 5%, neumann boundary conditions and gaussian kernel.
[gmic]./ Draw image [0] at (0,0,0,0) on image [1], with opacity 1 and mask [2].
[gmic]./ Keep image [1] (1 image left).
[gmic]./ Output image [0] as jpg file '/dev/shm/composite.jpg', with quality 80% (1 image 512x512x1x3).
[gmic]./ End G'MIC interpreter.
Every command up to -image
lays the table for a three image pipeline. At the end of their run, the image list looks like this:
G’MIC image list
The -image
command selects the base image: “gradient”, the first argument, “pattern” references the sprite image. Four coordinates (0,0,0,0) position the upper left corner of the sprite. Four? Yes: G’MIC images are four dimensional, with width, height, slice, and spectral coordinates. An entire animation (or CAT scan) can be represented by a single G’MIC image with lots of slices (animation frames), and each slice can have an arbitrary spectrum of channels, each channel open to wide interpretation. See Image. 1
sets the opacity of the sprite image from the closed interval [0,…,1] — fully transparent ⇒ fully opaque. The last [mask] argument is a single channel, single slice image with pixels also in the closed interval [0,…,1]. The mask image argument is optional; in its absence, the opacity argument provides a constant value function to render the sprite (partially) opaque. At the end of the day, the “gradient” image should look like this and should demonstrate blending of the sprite onto the base per the values in mask:
Results of image
command
Your scope of activity lies entirely in the realm of generating masks; At this juncture, I don’t think it is too hard a reach for you to generate a knockout mask from your depth data sets. If I’m wrong, and your attempts at mask generation through G’MIC all crash-and-burn, post what you tried to do here and we’ll try to help.
Aye, there’s the rub: You all can easily imagine what you want to do, but how do those imagined steps map to G’MIC commands? Start Here tries to move people forward from that initial quandry. At any point you can type gmic -h
<some command> and get a terse overview of what the command does. Try it on the commands listed in the swipe.
Hope this is enough to get you into serious trouble.