Skip to content

Instantly share code, notes, and snippets.

@tai2
Created October 11, 2012 12:24
Show Gist options
  • Save tai2/3871969 to your computer and use it in GitHub Desktop.
Save tai2/3871969 to your computer and use it in GitHub Desktop.
swap each color band of image
import Image
def bandswap(pr,pg,pb):
im = Image.open('Lenna.png')
b = im.split()
im = Image.merge('RGB', (b[pr], b[pg], b[pb]))
im.save('Lenna_%d%d%d.png'%(pr,pg,pb));
if __name__ == '__main__':
bandswap(0,1,2)
bandswap(1,2,0)
bandswap(2,0,1)
bandswap(2,1,0)
bandswap(0,2,1)
bandswap(1,0,2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment