Page 1 of 1

Swap image color channels based off noise image.

Posted: 2017-12-16T09:30:15-07:00
by coolperez8
So, here's what I want to do.

Let's say I have a normal image with RGB color channels. I want to either generate or use a random noise image for this. Basically, what I want to do is switch the red and green color channels based off the noise image's pixels. If the pixel is black the colors aren't switched, if it's white the colors are completely swapped, and if it's half/gray the colors are averaged. How can I do this?

Re: Swap image color channels based off noise image.

Posted: 2017-12-16T10:03:12-07:00
by snibgo
With a "compose over". The basic idea is:

Code: Select all

convert ^
  source.png ^
  switched.png ^
  mask.png ^
  -compose Over -composite ^
  out.png
Where the mask is black, the output is from source. Where it is white, it is from switched. Where it is gray, the output is a blend.

Instead of "switched.png", you could start a new list, clone the source, separate the channels, swap them, and combine:

Code: Select all

convert ^
  source.png ^
  ( +clone ^
    -separate ^
    -swap 0,1 ^
    -combine ^
  ) ^
  mask.png ^
  -compose Over -composite ^
  out.png
(Windows syntax, but untested.)