1
votes

I have 7 images with same size, orientations, color space.

I am trying convert 6 of them to LinearGray and combine every three images to RGB (RGB_1 and RGB_2). After this I need to Subtract RGB_1 from the 7th image and Add RGB_2 to the result.

magick.exe ( AAA.png BBB.png CCC.png -colorspace LinearGray ) -combine RES.tga

is working as expected, but

magick.exe ( ( AAA.png BBB.png CCC.png -colorspace LinearGray ) -combine ) GGG.png -compose minus_dst RES.tga

or

magick.exe ( ( AAA.png BBB.png CCC.png -colorspace LinearGray ) -combine ) -compose minus_dst GGG.png RES.tga

always creates two outputs, RES-0.tga and RES-1.tga, where one of these is the combined RGB image and the second is a grayscale version of GGG.png.

I even can't go to a next step to Add RGB_2 combined image.

What am I doing wrong and how can I fix it?

Thank you.

1
The -compose minus_dst just sets the composition method. You still have to do -composite right after that to do the actual operation.GeeMack
Did my answer sort out your problem? If so, please consider accepting it as your answer - by clicking the hollow tick/checkmark beside the vote count. If not, please say what didn't work so that I, or someone else, can assist you further. Thanks. meta.stackexchange.com/questions/5234/…Mark Setchell

1 Answers

1
votes

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.