Your question hasn't had much attention, so I wanted to help you along a bit. One thing you can use to make life easier and processing faster is to use Magick Persistent Registers (MPR) which are named lumps of memory where you can create stuff, set it aside with a name and then refer back to it later - very handy for more complicated workflows - and much faster than writing to disk and starting a new process.
So, here's how you can combine your first 3 images to form a single image and set it aside as "left" in an MPR, do the same with the next 3 images, and set them aside as "right" in an MPR, and then recall the two images and place them side-by-side. It is a bit artificial, but it demonstrates what I am suggesting. I also write an intermediate PNG file for debug purposes:
magick 1.png 2.png 3.png -combine -write "left.png" -write MPR:left +delete ^
4.png 5.png 6.png -combine -write "right.png" -write MPR:right +delete ^
MPR:left MPR:right +append result.png
Notice also that I didn't need any parentheses because I deleted the first combined image so there was nothing left in the image stack before I added [4-6].png
So, getting back to your question, you probably want something more like this:
magick 1.png 2.png 3.png -colorspace lineargray -combine -write "RGB1.png" -write MPR:RGB1 +delete ^
4.png 5.png 6.png -colorspace lineargray -combine -write "RGB2.png" -write MPR:RGB2 +delete ^
MPR:RGB1 7.png -compose minus_dst -composite ^
MPR:RGB2 -compose add -composite result.png
Of course, you would remove the -write
of the intermediate, debug images in production code.
You could speed this up a tiny bit by doing the second line first, followed by the first line. If you did that you wouldn't need to save the MPR:RGB1 and reload it because it would already be in the image stack ready for the subtraction, but the difference is probably tiny and this way is nearer to your thought process. And it's already much better than 3 separate commands and three separate processes with intermediate disk files, so let's not worry too much.
-compose minus_dst
just sets the composition method. You still have to do-composite
right after that to do the actual operation. – GeeMack