
img = produce_image_layer_from_real_image("image_sqrpnt.png")
+img = produce_image_layer_from_real_image("cat-512.png")
shares = img.produce_two_shares_from_image()
plot_matrix(shares[0], title='first transparent')
@@ -11917,2432 +11927,2427 @@ can be recover.
@@ -14386,2436 +14391,2428 @@ Wu7CeuXKlStXrly5cuVXy11Yr1y5cuXKlStXrvxquQvrlStXrly5cuXKlV8td2G9cuXKlStXrly5
@@ -16860,1905 +16857,1644 @@ cuXKlStXfrXchfXKlStXrly5cuXKr5b/A6MqeB2XuAzNAAAAAElFTkSuQmCC
@@ -18802,7 +18538,7 @@ know the original message from the cypher.
@@ -18812,7 +18548,7 @@ know the original message from the cypher.
fig, (ax0, ax1, ax2 ) = plt.subplots(ncols=3)
-img=matplotlib.image.imread('sqrpnt_logo.png')
+img=matplotlib.image.imread('calvin_pixels.png')
do_not_show_axis(ax0)
ax0.imshow(img)
+
show_sub_pixel([[white]*10]*10, ax=ax1, title="transparent 1")
show_sub_pixel([[white]*10]*10, ax=ax2, title="transparent 2")
cheated = produce_image_layer_from_real_image("cheatedimage_sqrpnt.png")
+cheated = produce_image_layer_from_real_image("dog-512.png")
cheated_share = cheated.produce_cheated_image_from_other_share(shares[0])
plot_matrix(cheated_share , title='crafted transparent')
@@ -24305,2440 +27617,2432 @@ a cheater could show whatever he wants as a results
@@ -26773,1739 +30077,1916 @@ ypUrV75a7sJ65cqVK1euXLly5avl/wGK5STDARVNcgAAAABJRU5ErkJggg==
@@ -30351,7 +33832,7 @@ kqSi/R/wvyW/R3XWDwAAAABJRU5ErkJggg==
-In [49]:
+In [22]:
fig, ax = plt.subplots()
@@ -33877,7 +37358,7 @@ AAAAAACIFIlnAAAAAAAAAECk/j8JfHXYEoPjfwAAAABJRU5ErkJggg==
-In [48]:
+In [25]:
fig, ax = plt.subplots()
@@ -34485,7 +37966,7 @@ jHhWi9MpAAAAAElFTkSuQmCC
-In [47]:
+In [26]:
fig, ax = plt.subplots()
@@ -37748,7 +41229,7 @@ an article publish by Fiat and Shamir in the year of grace 1987.
-In [46]:
+In [27]:
fig, (ax0, ax1, ax2 ) = plt.subplots(ncols=3)
@@ -43745,6 +47226,18 @@ without giving $\omega$ such that $\omega ^2 = x$
+
+
+
+
+
+
+
+
@@ -43763,6 +47256,22 @@ without giving $\omega$ such that $\omega ^2 = x$
+
+
+
+
+In [ ]:
+
+
+
+
+
+
+
+
+
+
+
diff --git a/visual_cryptography/visual_cryptography.py b/visual_cryptography/visual_cryptography.py
index e50a776..51e6c1d 100644
--- a/visual_cryptography/visual_cryptography.py
+++ b/visual_cryptography/visual_cryptography.py
@@ -22,8 +22,8 @@ class ImageLayer(object):
[[0,1,1,0], [1,0,0,1]],
[[1,0,0,1], [0,1,1,0]],
)
-
- pixel_width = 2
+
+ pixel_width = 2
def __init__(self, height, width):
self.data = self.get_empty_data(height, width)
@@ -41,10 +41,10 @@ class ImageLayer(object):
sub_pixel_matrix = self.c_0[0]
number_of_share_to_produce = len(sub_pixel_matrix)
number_of_sub_pixels = len(sub_pixel_matrix[0])
-
+
current_width = len(self.data[0])
current_height = len(self.data)
-
+
ret = [self.get_empty_data(current_height * self.pixel_width, current_width * self.pixel_width) for i in range(len(sub_pixel_matrix))]
return ret
@@ -93,29 +93,35 @@ class ImageLayer(object):
return cheated_share
-def cmyk_to_luminance(r, g, b):
+def cmyk_to_luminance(r, g, b, a):
"""
takes a RGB color and returns it grayscale value. See
- http://www.johndcook.com/blog/2009/08/24/algorithms-convert-color-grayscale/
+ http://www.johndcook.com/blog/2009/08/24/algorithms-convert-color-grayscale/
for more information
"""
- return 0.299 * r + 0.587 * g + 0.114 * b
+ if (r, g, b) == (0, 0, 0):
+ return a
+ return (0.299 * r + 0.587 * g + 0.114 * b) * a / 255
-def cmyk_to_black_and_white(r, g, b):
- black_threshold = 255 / 3
- if cmyk_to_luminance(r, g, b) > black_threshold:
+def cmyk_to_black_and_white(r, g, b, a):
+ black_threshold = 255 / 2
+ if cmyk_to_luminance(r, g, b, a) < black_threshold:
return 0
return 1
def produce_image_layer_from_real_image(image_path):
- im = Image.open(image_path).convert('RGB')
+ im = Image.open(image_path).convert('RGBA')
ret = ImageLayer(*im.size)
+ d = {}
for i in range(im.size[0]):
for j in range(im.size[1]):
- r, g, b = im.im.getpixel((i,j))
- ret.data[j][i] = cmyk_to_black_and_white(r, g, b)
+ r, g, b, a = im.im.getpixel((i,j))
+ d[(r, g, b, a)] = cmyk_to_black_and_white(r, g, b, a)
+ ret.data[j][i] = cmyk_to_black_and_white(r, g, b, a)
return ret
-
-
\ No newline at end of file
+
+
+if __name__ == '__main__':
+ print(produce_image_layer_from_real_image('dog-512.png'))