Swap image color channels based off noise image.

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
coolperez8
Posts: 22
Joined: 2016-03-11T07:27:11-07:00
Authentication code: 1151

Swap image color channels based off noise image.

Post by coolperez8 » 2017-12-16T09:30:15-07:00

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?

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

Re: Swap image color channels based off noise image.

Post by snibgo » 2017-12-16T10:03:12-07:00

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

Post Reply