File size: 1,512 Bytes
06242ba 6aea31a 06242ba aeb01c6 1f2c04e aeb01c6 6aea31a aeb01c6 |
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 34 35 36 37 38 39 40 41 42 43 44 45 |
import gradio as gr
import stc
import numpy as np
import imageio
from scipy import signal
import cv2
from PIL import Image
title = "Steganography"
description = "Explore hiding messages in images using content adaptive steganography and STCs. Python implementation by Daniel Lerch https://github.com/daniellerch/pySTC"
def HILL(input_image, operation, message, key):
input_image.seek(0)
buffer = input_image.read()
I = cv2.imdecode(np.frombuffer(buffer, np.uint8), 1)
I = cv2.cvtColor(I,cv2.COLOR_BGR2GRAY)
cv2.imwrite('tmp/file.png',I)
if operation == 'decode':
stc.extract('tmp/file.png', key, 'tmp/output.txt')
return 'tmp/output.txt'
else:
H = np.array(
[[-1, 2, -1],
[ 2, -4, 2],
[-1, 2, -1]])
L1 = np.ones((3, 3)).astype('float32')/(3**2)
L2 = np.ones((15, 15)).astype('float32')/(15**2)
costs = signal.convolve2d(I, H, mode='same')
costs = abs(costs)
costs = signal.convolve2d(costs, L1, mode='same')
costs = 1/costs
costs = signal.convolve2d(costs, L2, mode='same')
costs[costs == np.inf] = 1
stc.embed('tmp/file.png', costs, message, key, 'tmp/stego.png')
return 'tmp/stego.png'
iface = gr.Interface(HILL,
["file", gr.inputs.Radio(["encode", "decode"]), "text", "text"],
"file",
title=title,
description=description)
iface.launch() |