abdulfatirs

SNToner.py | Sepia&Negative Effect in Images

May 6th, 2014
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. #! /usr/bin/env python
  2. # SNToner.py
  3. # Author: Abdul Fatir
  4.  
  5. from PIL import Image
  6. # Opening the Raw Image File
  7. raw_image = Image.open("raw.png")
  8. WIDTH,HEIGHT = raw_image.size
  9. # Creating Image objects for Sepia and Negative Images
  10. sepia_image = Image.new("RGB",(WIDTH,HEIGHT))
  11. neg_image = Image.new("RGB",(WIDTH,HEIGHT))
  12. # Loading Pixel Data for all images
  13. raw_pixels = raw_image.load()
  14. sepia_pixels = sepia_image.load()
  15. neg_pixels = neg_image.load()
  16.  
  17. for Y in range(HEIGHT):
  18.     for X in range(WIDTH):
  19.         # Getting RGB of each pixel
  20.         R,G,B = raw_pixels[X,Y]
  21.         oR = (R*.393) + (G*.769) + (B*.189)
  22.         oG = (R*.349) + (G*.686) + (B*.168)
  23.         oB = (R*.272) + (G*.534) + (B*.131)
  24.         # Writing pixel data after doing necessary manipulations
  25.         sepia_pixels[X,Y] = (int(oR),int(oG),int(oB))
  26.         neg_pixels[X,Y] = (255-R,255-G,255-B)
  27. # Saving the images
  28. sepia_image.save('sepia.png')
  29. neg_image.save('negative.png')
Advertisement
Add Comment
Please, Sign In to add comment