-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandLsb.py
More file actions
33 lines (29 loc) · 1004 Bytes
/
randLsb.py
File metadata and controls
33 lines (29 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: William
#
# Created: 23/09/2013
# Copyright: (c) William 2013
# Licence: <your licence>
#-------------------------------------------------------------------------------
import random as random
import scipy.ndimage as ndimg
import numpy as np
def randLsb(oimg,rate):
if rate == 0:
return oimg
img = np.empty_like(oimg)
img[:] = oimg
for i in xrange(0,len(img.flat)):
if random.random() < rate:
img.flat[i] ^= 0 if random.random() < 0.5 else 1
return img
def rand(imname,r,flatten=False):
return randLsb(np.uint8(ndimg.imread("../images/li_photograph/image.cd/" + imname[0] + "/" + imname + ".jpg", flatten=flatten)),r)
def main():
img = ndimg.imread("../images/li_photograph/image.cd/1/10000.jpg")
print (img == randLsb(img,1))
if __name__ == '__main__':
main()