0

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 :

  1. Load image bitmap and get image mat from it.
  2. Convert image from RGB to YCrCb
  3. Divide the image into blocks of 8 x 8 blocks.
  4. Center pixel values around 0 [0-255 => -128-127]
  5. Apply DCT transformation to get DCT coefficients for the block.
  6. Quantization [divide the DCT coefficients with quant matrix]
  7. Now substitute the LSBs of the non 0/1/DC coefficients with our secret message.
  8. inverse quantization
  9. inverse DCT
  10. [0-255 <= -128-127]
  11. YCbCr to RGB
  12. Get bitmap from image mat
  13. 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.
Utkarsh Singh
  • 51
  • 1
  • 7
  • At 11. Those look to me as two steps. Please make it two to make it clear at wich step happens what. – blackapps Mar 03 '21 at 09:05
  • Does/Can a Bitmap instance contain DCT Coefficients? – blackapps Mar 03 '21 at 09:08
  • `The data I just saved in the LSB of DCT coefficients gets destroyed int the 11th step` Those are two steps. In which one exactly? – blackapps Mar 03 '21 at 09:08
  • At step 0. Are you loading a jpg file in a bitmap? – blackapps Mar 03 '21 at 09:10
  • `saving the image as png.` Do you mean: compressing the bitmap to a png file? – blackapps Mar 03 '21 at 09:12
  • `I thought that the jpeg image I used ...` Do you mean: The jpg file where i start with? – blackapps Mar 03 '21 at 09:13
  • Yes if your camera app creates a jpg file of 4 MB and you load that file in a Bitmap instance and then compress it to jpg file again you end up with a different file size. Yes. – blackapps Mar 03 '21 at 09:21
  • `want a way to save the image without its data being destroyed` I think you want to save that bitmap. – blackapps Mar 03 '21 at 09:22
  • The jpeg algorithm does not involve steps 7-11. It also does not stop after 5. After 5 (and after you've modified the DCT coefficients), you're supposed to save said coefficients to a file in a very specific format, which is a lossless process. **THAT** is the jpeg algorithm. What you do is pixels -> DCT -> IDCT -> pixels. If you save said pixels to jpeg, the whole quantisation process will be run again, thus destroying your information. So save to bmp/png instead. – Reti43 Mar 03 '21 at 19:58
  • @blackapps At 11, those are two steps yes. The encoded data gets destroyed while saving the image as `jpeg` (compress it to jpeg). The Bitmap contains pixels that need to undergo jpeg compression algo to obtain DCT coefficients and then reverse that process to obtain the pixels in form of bitmap. `saving the image as png.` yes I mean compress bitmap to a png file. `I think you want to save that bitmap` I just want a jpeg image as output(which is similar in size to input image) with modified DCT coefficients . I just want the modification in DCT coeffs should not get destroyed while saving. – Utkarsh Singh Mar 04 '21 at 04:15
  • @blackapps At step 0, I have tried loading the image as bitmap using Android's default method. I have also tried it loading directly as `mat` using OpenCv `imread` function. Similiarly, I have tried saving the image by compressing the bitmap( first I have to get output bitmap from mat) and also directly saving the mat using `imwrite` of OpenCv. – Utkarsh Singh Mar 04 '21 at 04:21
  • @Reti43 `you're supposed to save said coefficients to a file in a very specific format, which is a lossless process` Can you please tell how I can do this? Is this same as [this](https://stackoverflow.com/a/42505881/12548269) (in this the file size increases 6 folds). DCT coeffs are used to hide the data in jpeg so that we can obtain a jpeg output, otherwise we can use normal LSB on jpeg image and save it as png. – Utkarsh Singh Mar 04 '21 at 04:34
  • @Reti43 I'm saving the data in lsb of coefficients which were not made 0/1 by quantisation. So even if we rerun quantisation using the same quantisation table it should remain intact. (I tried using image compressed by android to hide data to ensure same quantisation table. - less data was destroyed but still it was) I recently learned about all this, so forgive me if I used stated some wrong information. Thanks for all the help. – Utkarsh Singh Mar 04 '21 at 04:36
  • `At step 0, I have tried loading the image as bitmap using Android's default method` ??? The image? An image file i think. What kind of file? And what is 'Androids default method'? Not that it matters i think. – blackapps Mar 04 '21 at 07:21
  • `12. Save the image as jpeg.` Save the bitmap as jpeg i think. – blackapps Mar 04 '21 at 07:22
  • @blackapps the default method is the first one mentioned in `Somethings I have tried` and yes I meant save bitmap as jpeg. sorry. – Utkarsh Singh Mar 05 '21 at 04:27

0 Answers0