]> AND Private Git Repository - canny.git/blobdiff - stc/exp/raphus/sobel555_for_ensemble.py
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
ajout style
[canny.git] / stc / exp / raphus / sobel555_for_ensemble.py
index 89e0cbdd39d07aa7bc39d413c1ce4004607af201..4a31c2028160f9a1e05988c90a399b7a56c26309 100644 (file)
@@ -429,7 +429,7 @@ def compute_filter_canny(level,image,MsgLen):
     processed= array(processed.getdata()).flatten()
     List7=set(compute_list_bit_to_change(100,processed))
 
-    #nb_bit_embedded=(512*512/10)+40
+    
     nb_bit_embedded=max(2*MsgLen,int(len(List3)/MsgLen)*MsgLen)
     print "nb_bit_embedded",nb_bit_embedded
     AvailablePixel3=List3
@@ -458,9 +458,9 @@ def compute_filter_canny(level,image,MsgLen):
         sub = range(len(level2))
 
 
-    #print "avail P3",len(AvailablePixel3)
-    #print "avail P5",len(AvailablePixel5)
-    #print "avail P7",len(AvailablePixel7)
+    print "avail P3",len(AvailablePixel3)
+    print "avail P5",len(AvailablePixel5)
+    print "avail P7",len(AvailablePixel7)
 
 
     Weight=[0 for _ in sub]
@@ -489,10 +489,115 @@ def compute_filter_canny(level,image,MsgLen):
 
 
 
+def verifie(fileout,leng_msg,Message,):
+    global M,X
+    bit_to_read = 1
+    dd2 = im.open(fileout)
+    dd2 = dd2.convert('RGB') 
+    red2, green, blue = dd2.split()
+    level2=red2.copy()
+
+    [List_bit_to_change2,Weight2]=compute_filter_canny(level2,dd2,leng_msg)
+
+
+    level2= array(level2.getdata()).flatten()
+
+    print "support2",len(List_bit_to_change2)
+    print "message2",len(Message)
+    print "weight2",len(Weight2)
+
+    alpha = float(len(List_bit_to_change2))/len(Message)
+    assert alpha >= 2 
+    index = min(int(alpha),9)
+    H_hat2 = {
+        2 : [71,109],
+        3 : [95, 101, 121],
+        4 : [81, 95, 107, 121],
+        5 : [75, 95, 97, 105, 117],
+        6 : [73, 83, 95, 103, 109, 123],
+        7 : [69, 77, 93, 107, 111, 115, 121],
+        8 : [69, 79, 81, 89, 93, 99, 107, 119],
+        9 : [69, 79, 81, 89, 93, 99, 107, 119, 125]
+        }[index]
+
+
+    print H_hat2
 
 
+    Stc_message2=[getBit(level2[l],bit_to_read) for l in List_bit_to_change2]
+    LL2=list(List_bit_to_change2)
 
-def mystego(filein, fileout):
+    """
+    print "Level",max([level2[l]-level[l] for l in xrange(len(Stc_message2))])
+    print "List bit to change",max([LL2[l]-LL1[l] for l in xrange(len(Stc_message))])
+    print "Stc message", max([Stc_message[l]-Stc_message2[l] for l in xrange(len(Stc_message))])
+    """
+    Message2 = [x%2 for x in prod(H_hat2,len(Message),Stc_message2)] 
+    level2=Message2
+
+#    print "mesg",Message
+#    print "mesg2",Message2
+
+    l=0
+    val_mod2=0
+    list_msg=[]
+    decoded_msg=""
+
+
+
+    bbs = BlumBlumShub();
+    bbs.setN(M)
+    bbs.setSeed(X)
+
+    List_random=[]
+    while len(List_random)<len(Message2):
+        List_random.extend(Denary2Binary(bbs.next()))
+
+
+
+    MessageDecoded2=[(int(Message2[l])^int(List_random[l])) for l in xrange(len(Message2))]
+#    print conv_list_bit(''.join([`MessageDecoded2[i]` for i in xrange(leng_error*8)]))
+#    print int(conv_list_bit(''.join([`MessageDecoded2[i]` for i in xrange(leng_error*8)])))
+
+    #print "MessageDecoded2",MessageDecoded2
+    
+    outIm = im.new("L",im.open("invader.png").size)
+    (l,h) = outIm.size
+    print "taille de l'image",l*h
+    print "taille des donneées",len(MessageDecoded2)
+    queue = [255 if x != 0 else 0 for x in MessageDecoded2]
+    queue = queue[len(queue)-l*h:]
+    outIm.putdata(queue)
+    outIm.save("apresSobel.png")
+"""
+    print conv_list_bit(''.join([`MessageDecoded2[i]` for i in xrange(len(Message2))]))
+   for l in List_bit_to_change2:
+       if(val_mod2<leng_error*8):
+           list_msg.append(`getBit(level2[l],bit_to_read)^int(List_random[val_mod2])`)
+           if(val_mod2==leng_error*8-1):
+               bin_leng2=''.join(list_msg)
+               coded_msg2=conv_list_bit(bin_leng2)
+               clear_msg2=coded_msg2
+               length_msg=int(clear_msg2)
+               list_msg=[]
+       if(val_mod2>=leng_error*8 and val_mod2<leng_error*8+length_msg*leng_error):
+           list_msg.append(`getBit(level2[l],bit_to_read)^int(List_random[val_mod2])`)
+           if(len(list_msg)==leng_error*8):
+               pack=''.join(list_msg)
+               msg=conv_list_bit(pack)
+               decoded_msg=decoded_msg+msg
+               list_msg=[]
+       val_mod2+=1
+       l=l+1
+       print decoded_msg#[0:20]
+"""
+
+
+
+
+
+def mystego(filein, fileout,file_msg="invader"):
     bit_to_read = 1
     global M,X
     bbs = BlumBlumShub();
@@ -503,6 +608,8 @@ def mystego(filein, fileout):
     dd = dd.convert('RGB') 
     red, green, blue = dd.split()
     level=red.copy()
+    
+    #print type(level),level
 
 
     """
@@ -537,7 +644,7 @@ def mystego(filein, fileout):
     """    
 
 
-
+    
     message = []
     for c in [x if x==0 else 1 for x in im.open("invader.png").getdata()]:
         message +=[c]
@@ -552,15 +659,16 @@ def mystego(filein, fileout):
     #print List_pack
 
     leng_msg=len(List_pack)
+    print "leng_msg",leng_msg
 
     [List_bit_to_change,Weight]=compute_filter_canny(level,dd,leng_msg)
     level= array(level.getdata()).flatten()
    
     List_random=[]
-    while len(List_random)<len(List_bit_to_change):
+    while len(List_random)<len(List_pack):
         List_random.extend(Denary2Binary(bbs.next()))
 
-        
+
 
     #print List_bit_to_change
     Support=[]
@@ -573,11 +681,16 @@ def mystego(filein, fileout):
     Message=[(int(List_pack[l])^int(List_random[l])) for l in xrange(len(List_pack))]
 
     #print "support",len(List_bit_to_change)
-    #print "message",len(Message)
+    #print "message",Message
     #print "weight",len(Weight)
 
+    #(x_b,Stc_message,H_hat) = stc(Support,Weight,Message)
+    
     (x_b,Stc_message,H_hat) = stc(Support,Weight,Message)
 
+    print "comparaison entre stc_message et message", len(Stc_message),len(Message)
+
+
     #print "pourcentage modif",nbdif(x_b,Stc_message)
     #print "taille Stc_message",len(Stc_message)
 #    Stc_message=Message
@@ -609,129 +722,25 @@ def mystego(filein, fileout):
     zz3.save(fileout)
     #zz4.show()
 
+    verifie(fileout,leng_msg,Message)
 
-    """
-    
-    dd2 = im.open(fileout)
-    dd2 = dd2.convert('RGB') 
-    red2, green, blue = dd2.split()
-    level2=red2.copy()
-
-    [List_bit_to_change2,Weight2]=compute_filter_canny(level2,dd2,leng_msg)
-
-
-    level2= array(level2.getdata()).flatten()
-
-    print "support2",len(List_bit_to_change2)
-    print "message2",len(Message)
-    print "weight2",len(Weight2)
-
-    alpha = float(len(List_bit_to_change2))/len(Message)
-    assert alpha >= 2 
-    index = min(int(alpha),9)
-    H_hat2 = {
-        2 : [71,109],
-        3 : [95, 101, 121],
-        4 : [81, 95, 107, 121],
-        5 : [75, 95, 97, 105, 117],
-        6 : [73, 83, 95, 103, 109, 123],
-        7 : [69, 77, 93, 107, 111, 115, 121],
-        8 : [69, 79, 81, 89, 93, 99, 107, 119],
-        9 : [69, 79, 81, 89, 93, 99, 107, 119, 125]
-        }[index]
-
-
-    print H_hat,H_hat2
-
-
-    Stc_message2=[getBit(level2[l],bit_to_read) for l in List_bit_to_change2]
-    LL1=list(List_bit_to_change);
-    LL2=list(List_bit_to_change2)
-
-    print "Level",max([level2[l]-level[l] for l in xrange(len(Stc_message2))])
-    print "List bit to change",max([LL2[l]-LL1[l] for l in xrange(len(Stc_message))])
-    print "Stc message", max([Stc_message[l]-Stc_message2[l] for l in xrange(len(Stc_message))])
-
-    Message2 = [x%2 for x in prod(H_hat2,len(Message),Stc_message2)] 
-    level2=Message2
-
-#    print "mesg",Message
-#    print "mesg2",Message2
-
-    print equiv(Message,Message2)
 
-    print "fini"
-
-    l=0
-    val_mod2=0
-    list_msg=[]
-    decoded_msg=""
-
-    MessageDecoded2=[(int(Message2[l])^int(List_random[l])) for l in xrange(len(Message2))]
-#    print conv_list_bit(''.join([`MessageDecoded2[i]` for i in xrange(leng_error*8)]))
-#    print int(conv_list_bit(''.join([`MessageDecoded2[i]` for i in xrange(leng_error*8)])))
-
-    print "MessageDecoded2",MessageDecoded2
-    print conv_list_bit(''.join([`MessageDecoded2[i]` for i in xrange(len(Message2))]))
-
-
-    
-
-
-#    for l in List_bit_to_change2:
-#        if(val_mod2<leng_error*8):
-#            list_msg.append(`getBit(level2[l],bit_to_read)^int(List_random[val_mod2])`)
-#            if(val_mod2==leng_error*8-1):
-#                bin_leng2=''.join(list_msg)
-#                coded_msg2=conv_list_bit(bin_leng2)
-#                clear_msg2=coded_msg2
-#                length_msg=int(clear_msg2)
-#                list_msg=[]
-#        if(val_mod2>=leng_error*8 and val_mod2<leng_error*8+length_msg*leng_error):
-#            list_msg.append(`getBit(level2[l],bit_to_read)^int(List_random[val_mod2])`)
-#            if(len(list_msg)==leng_error*8):
-#                pack=''.join(list_msg)
-#                msg=conv_list_bit(pack)
-#                decoded_msg=decoded_msg+msg
-#                list_msg=[]
-#        val_mod2+=1
-#        l=l+1
-
-    print decoded_msg#[0:20]
-    print len(List_bit_to_change)
-    list_nb_bit.append(filein)
-    list_nb_bit.append(len(List_bit_to_change2))
-
-"""
-
-
-#path_cover = '/localhome/couturie/ensemble/cover_bad_laplace/'
-path_stego = '/home/couchot/rech/CCG12/canny/stc/exp/raphus/stego/'
-path_cover = '/home/couchot/rech/BCG10/Oxford11/experiments/images/'
-#path_stego = '/tmp/'
-#path_stego = '/home/couturie/BossBase-1.0-canny/'
-#listing = os.listdir(path_cover)
-
-
-list_nb_bit=[]
-l=0
 
 
 
 # entree sortie 
+def main(): 
+    path_stego = '/home/couchot/rech/CCG12/canny/stc/exp/raphus/stego/'
+    path_cover = '/home/couchot/rech/BCG10/Oxford11/experiments/images/'
+    list_nb_bit=[]
+    l=0
+    listing = [957, 108, 106, 29, 431, 924, 262, 477, 346, 809]
+    for infile in listing:
+        #    if l<10:
+        fi = path_cover+str(infile)+'.png'
+        fo = path_stego+str(infile)+'.png'
+        mystego(fi,fo)
+        l+=1
 
-
-listing = [957, 108, 106, 29, 431, 924, 262, 477, 346, 809]
-
-for infile in listing:
-#    if l<10:
-    fi = path_cover+str(infile)+'.png'
-    fo = path_stego+str(infile)+'.png'
-    mystego(fi,fo)
-    l+=1
-
-#f = open('histogram_boss_canny_100255', 'w')
-#f = open('histogram', 'w')
-#for item in list_nb_bit:
-#f.write("%s\n" % item)
+if __name__ == "__main__":
+    main()