SHARE
TWEET
LSB_cleaner.py
a guest
Aug 13th, 2015
247
Never
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # Requirements:
- # Install Python 2.7 from https://www.python.org/
- # Install Python Imaging Library from http://www.pythonware.com/products/pil/
- #
- # Usage:
- # Open a terminal and navigate to the directory where you saved this script.
- # Run the command:
- # python this_script.py /path/to/image/file.png
- #
- # What it does:
- # This script creates 4 new images from the original.
- # [filename].red.png, [filename].green.png, and [filename].blue.png contain the LSB planes from the original image.
- # [filename].clean.png contains a copy of the original image with the LSB planes all set to zero.
- #
- import sys
- from PIL import Image
- colors = ["red","green","blue"]
- def triplet(i, v):
- return ((i==0)*v, (i==1)*v, (i==2)*v)
- def clean_pixel(pix):
- return tuple([((x>>1)<<1) for x in pix])
- def main():
- # Load the original image
- im = Image.open(sys.argv[1])
- data_in = im.getdata()
- # Generate the LSB images
- for i in range(3):
- out = Image.new("RGB", im.size)
- data_out = [triplet(i,255*(x[i]%2)) for x in data_in]
- out.putdata(data_out)
- out.save(sys.argv[1]+"."+colors[i]+".png")
- # Generate the clean image
- clean = Image.new("RGB", im.size)
- data_clean = [clean_pixel(x) for x in data_in]
- clean.putdata(data_clean)
- clean.save(sys.argv[1]+".clean.png")
- return 0
- if __name__ == '__main__':
- main()
RAW Paste Data
