Since I’ve only recently came to software and documentation is so huge, still can’t figure it out how to do stuff. I need to automatically batch process image, and doing the stuff in GIMP manually is tedious. So, there are two images: input and output. Both have RGBA channels. I need to do as follows:
Copy input’s alpha channel to output’s red
Copy input’s blue channel to output’s green
Copy input’s green channel to output’s blue
Copy input’s red channel to output’s alpha
Curve level output’s red channel with input 255 and output 180 (or multiply each pixels by 0.707)
Value invert output’s green channel
Curve level output’s blue channel with input 0 and output 128 (basically, need to make pixels values scaled to 128-255 range)
@eksdee Welcome to the forum. It took me a while to learn how G’MIC works. May I ask which version you are using? I am using the dev version of 2.9.0pre, so the syntax may vary if you are using an ancient version. Basic workflow.
1-4 Separate and reverse channel order. gmic input.png split c reverse
4-7 Indexing operations. After the reversal, images are in R,G,B,A order and so will be [0],[1],… mul[0] {180/255} negate[1] normalize[2] 128,255
8 Combine channels and save. append c output output.png
If you are looking to do a batch operation, you could wrap it with a repeat $! local[$>] ... endlocal done loop. $! means total number of images and $> counts up the image index. Combined with input_glob at the beginning, which can glob a certain set of images from your folder, you have a working command.
Something which is probably not so easy is to think about the easiest/simplest way to do something in G’MIC. There are many possibilities of doing the same thing, and as with any other programming language, the script writer has to figure out what technique suits the most his needs.
I know The fact you proposed a completely different approach to the OP problem made me realize this. That’s interesting to see different approaches from different people.
Copy input’s alpha channel to output’s red $ gmic input.png sh[0] 0 f. i3#-2 rm.
Copy input’s blue channel to output’s green $ gmic input.png sh[0] 1 f. i2#-2 rm.
Copy input’s green channel to output’s blue $ gmic input.png sh[0] 2 f. i1#-2 rm.
Copy input’s red channel to output’s alpha $ gmic input.png sh[0] 2 f. i1#-2 rm.
Curve level output’s red channel with input 255 and output 180 (or multiply each pixels by 0.707) $ gmic input.png sh[0] 0 *. .707 rm.
Value invert output’s green channel $ gmic input.png sh[0] 1 f. 255-i rm.
Curve level output’s blue channel with input 0 and output 128 (basically, need to make pixels values scaled to 128-255 range) $ gmic input.png sh[0] 1 f. i/2+128 rm.
Save output image on disc $ gmic input.png sh[0] 1 f. i/2+128 rm. o output.png
You could remove[0] by the way if you have only one image. Otherwise, repeat $! l[$>] endl done would be needed using this approach.