Esempio n. 1
0
def extractmsg(sed, im, perc):
    total = 0.0
    w,h = im.size
    size = w * h
    se = rand_sequece(sed, int(size*perc), True)
    rand_list = random_walk(sed, size, size-1)
    r = get_gauss_seq(sed, size-1, 0, 1.5, 5)
    s = get_gauss_seq(2+sed, size-1, 0, 1.5, 5)
    i = 0
    j = 0
    while i < len(se):
        while True:
            x = rand_list[i+j] / w
            y = rand_list[i+j] % w
            pixel = im.getpixel((x, y))
            # k = 0 
            if not parity_func(pixel, r[i+j]-s[i+j]):
                j += 1
                continue
            elif parity_func(pixel, r[i+j]-s[i+j]) == se[i]:
                total += 1
                break
            else:
                break
        i+=1
    print "Extract pixel:%d" %(i+j)
    print "Total:%d Extract Percent:%f" %(total, total/(size*perc))
Esempio n. 2
0
def extratlsb(sed, im, perc):
    w,h = im.size
    size = w * h
    se = rand_sequece(sed, int(size * perc), False)
    origin_list = random_walk(sed, size, len(se))
    sim = 0
    for s, r in zip(se, origin_list):
        x = r / w
        y = r % w
        pixel = im.getpixel((x, y))
        if pixel & 1 == s:
            sim += 1
    return sim / float(len(se))
Esempio n. 3
0
def lsb_replace(sed, im, perc):
    nim = im.copy()
    w,h = im.size
    size = w * h
    se = rand_sequece(sed, int(size * perc), False)
    rand_list = random_walk(sed, w*h, int(size * perc))
    s = set(rand_list);
    for s, r in zip(se, rand_list):
        x = r / w;
        y = r % w;
        pixel = nim.getpixel((x, y))
        pixel = (pixel & 0xfe) | s
        nim.putpixel((x, y), pixel);
    fn = (re.search("[0-9]*\.(.*)", im.filename)).group(0)
    path = 'result/' + im.format + '/' + str(perc) + '_' + fn 
    nim.save(path)      #profile needed to store otherwise the brightness would not same.
    return nim, path
Esempio n. 4
0
def embedmsg(sed, im, perc):
    nim = im.copy()
    w,h = nim.size
    size = w * h
    msglen = int(size * perc)
    rand_list = random_walk(sed, size, size-1)
    se = rand_sequece(sed, msglen, True)
    print "Len :%d" %len(se)
    r = get_gauss_seq(sed, size-1, 0, 1.5, 5)
    s = get_gauss_seq(2+sed, size-1, 0, 1.5, 5)
    i = 0
    # j is used to hide message when k = 0 and find next pos.
    j = 0
    # Add 
    while i < len(se):
        while True:
            x = rand_list[i+j] / w
            y = rand_list[i+j] % w
            pixel = nim.getpixel((x, y))
            k = r[i+j] - s[i+j]
            # k = 0 then pixel = x+r
            if not parity_func(pixel + r[i+j], k):
                pixel = checkbound(pixel, r[i+j], k, se[i])
                nim.putpixel((x,y), pixel)
                j += 1
                continue
            elif parity_func(pixel + r[i+j], k) == se[i]:
                pixel = checkbound(pixel, r[i+j], k, se[i])
                nim.putpixel((x,y), pixel)
                break
            else:
                pixel = checkbound(pixel, s[i+j], k, se[i])
                nim.putpixel((x,y), pixel)
                break

        i += 1;
    print "embeded pixel:%d" %(i+j)
    fn = (re.search("[0-9]*\.(.*)", im.filename)).group(0)
    path = 'result_stm/' + im.format + '/' + str(perc) + '_' + fn 
    nim.save(path)      #profile needed to store otherwise the brightness would not same.
    return nim, path
Esempio n. 5
0
    for s, r in zip(se, origin_list):
        x = r / w
        y = r % w
        pixel = im.getpixel((x, y))
        if pixel & 1 == s:
            sim += 1
    return sim / float(len(se))

if __name__ == "__main__":
    y1 = []
    y2 = []
    y3 = []
    
    im = Image.open("test_images/png/1.png")
    fn,path = lsb_replace(3, im, 0.5)
    print rand_sequece(1, 100, True)
    print extratlsb(3, fn, 0.5)
    y1.append(sample_analyze(fn))
    im.close()
    fn.close()
    '''
    for i in getallfile('test_images/jpeg/'):
        im = Image.open(i)
        fn = lsb_replace(3, im, 0.5)
        fn1 = lsb_replace(3, im, 0.25)
        fn2 = lsb_replace(3, im, 0.05)
        y1.append(sample_analyze(fn))
        y2.append(sample_analyze(fn1))
        y3.append(sample_analyze(fn2))
        im.close()
        fn.close()