Advertisement
abdulfatirs

SNToner.py | Sepia&Negative Effect in Images

May 6th, 2014
342
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. # E-Mail: abdulfatirs@gmail.com
  5.  
  6. from PIL import Image
  7. # Opening the Raw Image File
  8. raw_image = Image.open("raw.png")
  9. WIDTH,HEIGHT = raw_image.size
  10. # Creating Image objects for Sepia and Negative Images
  11. sepia_image = Image.new("RGB",(WIDTH,HEIGHT))
  12. neg_image = Image.new("RGB",(WIDTH,HEIGHT))
  13. # Loading Pixel Data for all images
  14. raw_pixels = raw_image.load()
  15. sepia_pixels = sepia_image.load()
  16. neg_pixels = neg_image.load()
  17.  
  18. for Y in range(HEIGHT):
  19.     for X in range(WIDTH):
  20.         # Getting RGB of each pixel
  21.         R,G,B = raw_pixels[X,Y]
  22.         oR = (R*.393) + (G*.769) + (B*.189)
  23.         oG = (R*.349) + (G*.686) + (B*.168)
  24.         oB = (R*.272) + (G*.534) + (B*.131)
  25.         # Writing pixel data after doing necessary manipulations
  26.         sepia_pixels[X,Y] = (int(oR),int(oG),int(oB))
  27.         neg_pixels[X,Y] = (255-R,255-G,255-B)
  28. # Saving the images
  29. sepia_image.save('sepia.png')
  30. neg_image.save('negative.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement