Beispiel #1
0
import numpy as np
import bpcs as bp

parser = ArgumentParser()
parser.add_argument("-i", "--image", type=str, help="encoded image path")
parser.add_argument("-s", "--secret", type=str, help="secret text file path")
parser.add_argument("-o", "--output", type=str, help="output text file path")
parser.add_argument("--verbose", action="store_true", help="verbose")
args = parser.parse_args()

blocksize = (8, 8)
ath = 0.45  # complexity threshold

if args.image:
    arr = bp.read_image_as_numpy(args.image)
    arr = bp.to_binary(arr)

    COLOR = 1
    if len(arr.shape) == 4:  # RGB
        COLOR = 3
    elif len(arr.shape) == 3:  # gray-scale
        arr = arr.reshape(arr.shape[:2] + (
            1,
            arr.shape[2],
        ))
        COLOR = 1
    else:
        print("Unsupported shape of image")
        exit(1)
    n_valid_blocks = 0
Beispiel #2
0
import sys
import numpy as np
import bpcs as bp

from PIL import Image

if len(sys.argv) < 3:
    print("USAGE: {0} <IPATH> <SPATH>".format(sys.argv[0]))
    print("    IPATH:  image path")
    print("    SPATH:  secret file path")
    exit(1)

IPATH = sys.argv[1]
SPATH = sys.argv[2]

blocksize = (8, 8)
ath = 0.45  # complexity threshold

# prepare secret blocks
arr = bp.read_message_as_numpy(SPATH, blocksize)
arr = bp.to_binary(arr)
secret_blocks, conj_map = bp.secret_blocks(arr, blocksize, ath)

# encode
arr = bp.read_image_as_numpy(IPATH)
arr = bp.to_binary(arr)
arr = bp.encode(arr, secret_blocks, conj_map, blocksize, ath)
arr = bp.to_image(arr)
Image.fromarray(np.uint8(arr)).show()
Image.fromarray(np.uint8(arr)).save("images/encoded.png")