Luca Giorgi
Luca Giorgi

Reputation: 1010

Split and shift RGB channels in Python

What I'm trying to do is recreating what is commonly called an "RGB shift" effect, which is very easy to achieve with image manipulation programs.

I imagine I can "split" the channels of the image by either opening the image as a matrix of triples or opening the image three times and every time operate just on one channel, but I wouldn't know how to "offset" the channels when merging them back together (possibly by creating a new image and position each channel's [0,0] pixel in an offsetted position?) and reduce each channel's opacity as to not show just the last channel inserted into the image.

Has anyone tried to do this? Do you know if it is possible? If so, how did you do it?

Thanks everyone in advance!

Upvotes: 1

Views: 1560

Answers (1)

user1196549
user1196549

Reputation:

Per color plane, replace the pixel at (X, Y) by the pixel at (X-1, Y+3), for example. (Of course your shifts will be different.)

You can do that in-place, taking care to loop by increasing or decreasing coordinate to avoid overwriting.

There is no need to worry about transparency.

Upvotes: 2

Related Questions