Page 1 of 1

Faster alternative to FX with color channels?

Posted: 2019-09-20T14:42:16-07:00
by WorldOfDepth
Hi All: a quick and maybe somewhat newbie question (if so, sorry) for you: I'm trying to implement the Dubois method of making color anaglyphs. I've been able to do it using multiple FX commands as follows:

Code: Select all

convert right.jpg left.jpg -channel r -fx '+u.r*.456 + u.g*.5 + u.b*.176 - v.r*.043 - v.g*.088 - v.b*.002' -separate i-r.jpg
convert right.jpg left.jpg -channel g -fx '-u.r*.04 - u.g*.038 - u.b*.016 + v.r*.378 + v.g*.734 - v.b*.018' -separate i-g.jpg
convert right.jpg left.jpg -channel b -fx '-u.r*.015 - u.g*.021 - u.b*.005 - v.r*.072 - v.g*.113 + v.b*1.226' -separate i-b.jpg
convert i-r.jpg i-g.jpg i-b.jpg -gamma 1.5 -channel rgb -combine $1-anad.jpg
I know it's possible to do this in a single command, but I wanted the intermediate files to gauge progress, because this is *very* slow for any decent-sized image. I see the faster 'evaluate' option, but I don't think I can use it here, unless I do each operation separately, for 18 commands, right? Is there another method that could do this faster than pixel-by-pixel FX? Thanks for any help!

P.S. This is IM 7.0.8-3.

Re: Faster alternative to FX with color channels?

Posted: 2019-09-20T16:18:26-07:00
by fmw42
Perhaps you do not need -fx. Can you not do it with multiple uses of -color-matrix and composites, for example. See https://imagemagick.org/script/command- ... lor-matrix

Re: Faster alternative to FX with color channels?

Posted: 2019-09-20T16:49:56-07:00
by snibgo
As Fred suggests, this can be done with colour matrices, one per input image, then add them together. Something like this. Untested, and add line-continuation characters and escape the parentheses and quote lists as required by your shell.

Code: Select all

magick
( right.jpg -color-matrix
  0.456, 0.5, 0.176
  -0.04, -0.038, -0.016
  -0.015, -0.021, -0.005
)
( left.jpg -color-matrix
  -0.043, -0.088, -0.002
  0.378, 0.734, -0.018
  -0.072, -0.113, 1.226 
)
-compose Plus -composite 
-gamma 1.5 $1-anad.jpg
EDIT: This needs an HDRI version of IM, because some intermediate values will be negative.

Re: Faster alternative to FX with color channels?

Posted: 2019-09-20T18:57:26-07:00
by fmw42
Thanks snibgo for filling in the details. I did not have time before.

Re: Faster alternative to FX with color channels?

Posted: 2019-09-24T22:56:24-07:00
by WorldOfDepth
Thank you, fmw42 and snibgo, that was exactly what I was looking for, and worked speedily like a charm! ⭐️