Faster alternative to FX with color channels?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
WorldOfDepth
Posts: 9
Joined: 2019-08-14T01:23:15-07:00
Authentication code: 1152

Faster alternative to FX with color channels?

Post by WorldOfDepth » 2019-09-20T14:42:16-07:00

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.
Last edited by WorldOfDepth on 2019-09-24T22:58:09-07:00, edited 1 time in total.

User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Faster alternative to FX with color channels?

Post by fmw42 » 2019-09-20T16:18:26-07:00

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

snibgo
Posts: 12157
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Faster alternative to FX with color channels?

Post by snibgo » 2019-09-20T16:49:56-07:00

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.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Faster alternative to FX with color channels?

Post by fmw42 » 2019-09-20T18:57:26-07:00

Thanks snibgo for filling in the details. I did not have time before.

WorldOfDepth
Posts: 9
Joined: 2019-08-14T01:23:15-07:00
Authentication code: 1152

Re: Faster alternative to FX with color channels?

Post by WorldOfDepth » 2019-09-24T22:56:24-07:00

Thank you, fmw42 and snibgo, that was exactly what I was looking for, and worked speedily like a charm! ⭐️

Post Reply