Stego / app.py
YassineYousfi
update stuff
600de08
raw history blame
No virus
2.08 kB
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 (Syndrome Trellis Codes).
http://dde.binghamton.edu/download/syndrome/ .
We use HILL https://ieeexplore.ieee.org/document/7025854 .
Python implementation adapted from Daniel Lerch's https://github.com/daniellerch/pySTC .
To encode:
Drag and drop a PNG file, write a message and enter a key (remember the key).
To decode:
Drap and drop the stego file, enter the key.
Note that this software is supplied "as is," without any services or guaranties.
'''
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', boundary='symm')
costs = abs(costs)
costs = signal.convolve2d(costs, L1, mode='same', boundary='symm')
costs = 1/costs
costs = signal.convolve2d(costs, L2, mode='same', boundary='symm')
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()