Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image, ImageFilter
- def get_num_bits_secret():
- return 1
- # im is the image you get when you combine the host image and the hidden image. (In this case, this was the image posted in the steamgifts thread).
- im = Image.open( 'combined.png' )
- num_bits_secret = get_num_bits_secret()
- def extract(im):
- width, height = im.size
- # iterate through the pixels
- for i in range(width):
- for j in range(height):
- pixel = list( im.getpixel((i,j)) )
- # for each color component
- for c in range(3):
- val = pixel[c]
- # "%" is the modulus operator. x % y gives you the remainder of dividing x by y.
- # "<<" and ">>" are bit shifting operators. They make a number lose binary digits at the right side, or add zeros at the right side.
- # e.g.: x >> 2, makes x lose two bits from the end (it's like dividing by 2^2 and taking only the quotient)
- # e.g.: x << 2, adds two 0 bits to the right of x (it's like multiplying by 2^2)
- # get the last num_bits_secret bits in that number
- val = (val % (1 << num_bits_secret))
- # move the number back to the left by placing zeros at the end.
- val = (val << (8 - num_bits_secret))
- pixel[c] = val
- # place the modified pixel back in the image.
- im.putpixel((i,j), tuple(pixel))
- return im
- ex = extract(im)
- ex.save('extracted.png')
- ex.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement