I'm trying to build an image steganography
android app to hide information in jpeg
images.
I'm encoding the information in the DCT Coefficients
of the image.
I'm using OpenCv
to perform the following steps :
- Load image bitmap and get image
mat
from it. - Convert image from RGB to YCrCb
- Divide the image into blocks of 8 x 8 blocks.
- Center pixel values around 0 [0-255 => -128-127]
- Apply DCT transformation to get DCT coefficients for the block.
- Quantization [divide the DCT coefficients with quant matrix]
- Now substitute the LSBs of the non 0/1/DC coefficients with our secret message.
- inverse quantization
- inverse DCT
- [0-255 <= -128-127]
- YCbCr to RGB
- Get bitmap from image
mat
- Save the bitmap as jpeg.
The idea is that since I'm just extracting and repacking a jpeg image using jpeg compression algo, the jpeg
compression algorithm should not destroy the data in the DCT coefficients (a lot of jpeg there :P)
Problem :
The data I just saved in the LSB of DCT coefficients gets destroyed int the 12th step. I want a way to save the image without its data being destroyed (which should be theoretically possible since I have followed the jpeg compression algorithm only.
Somethings I have tried :
- this is the normal method, which leads to dataloss.
- I used this method. It does not destroys the data, but it increases the file size by around 6 times and the final file received is not jpeg, it is pure bytes (which can be viewed in image viewer if the extension is set to jpeg or png)
- I thought that the jpeg image I used might have a different level of compression as compared to the one while saving the jpeg image by android. So I used the image saved by the app to hide data. Even in that a lot of data is lost(less compared to before).
- saving the image as png. This works, no data is lost and dct algorithm can be applied to extract the hidden information. But the point was to get a jpeg image as output, bcz jpeg is the most common image extension out there.