@afre, if I’ve understood well, this little script may solve your problem :
use_fill :
# Create input bayer image
sp lena rgb2bayer 0
# Use fill to decompose bayer image into distinct R,G,B channels.
100%,100%,1,3 # Recomposed RGB image with '0's.
50%,50%,1,3 # Spatially averaged RGB image.
# The trick here : we apply 'fill' on the bayer image to spread its values
# in the two created images, but we won't modify the bayer image itself.
f[0] "
const boundary = 1;
val = i;
x2 = int(x/2);
y2 = int(y/2);
!(x%2) && !(y%2) ? ( # val is R
I(#1,x,y) = [ val,0,0 ];
i(#2,x2,y2,0,0) = val;
):(x+y)%2 ? ( # val is G
I(#1,x,y) = [ 0,val,0 ];
Ga = (val + (y%2?j(1,-1):j(-1,1)))/2;
i(#2,x2,y2,0,1) = Ga;
):( # val is B
I(#1,x,y) = [ 0,0,val ];
i(#2,x2,y2,0,2) = val;
);
val # Trick : expression returns 'val' to avoid modification of image[0].
"
From a Bayer image, it renders a RGB image with 0 where pixels are unknown, and a half-sized image where known color values have been set or averaged at their correct position.
Just a note : when trying to implement custom things like this, never try to do it directly in the terminal. The terminal has its own substitution mechanisms and there are high chances you won’t be able to manage both G’MIC-specific and terminal-specific syntax at the same time (I don’t manage it personally).
I’d recommend them to define a custom G’MIC command in a G’MIC command file (possibly %APPDATA/user.gmic
and invoke this command from the command line).
At least you will only struggle with the G’MIC syntax alone
This is what the command above renders for me :