0

I'm trying to write a steganography applcation using the LSB method and it works so far well enough for a few image formats .

However it doesn't work for GIF images since i have noticed that the saved gif has a few different pixel values (usually +- 1) and the LSB method relies on changing the least significant bit so a few different values throws the decoding algorithm off.

i have tried using both imageio and PIL.Image and it's the same problem in both cases

So basically my question is : Why does the pixel values change when saved and is it even possible to use LSB for encoding and decoding a GIF ?

Thanks for your help.

khalsel
  • 9
  • 1
  • Does your gif have more than 255 colors? – Aran-Fey Jul 23 '18 at 10:26
  • Read [here](https://stackoverflow.com/questions/2336522/png-vs-gif-vs-jpeg-vs-svg-when-best-to-use) for more information about various image formats. GIF, while lossless, can support only up to 256 colours, compared to 256**3 = 16777216. – Reti43 Jul 23 '18 at 10:31
  • What i did was extract a gif and copy it with a modified first frame and the extracted images were in an array of RGB pixels (the example i used had (197,350,4) as dimentions) . so yeah i guess it is more than 256 colors. But why did the extracted images have more than 256 colors ? – khalsel Jul 23 '18 at 10:50
  • 1
    Because GIF is palette based, changing the LSB of a pixel can completely change which color is displayed. – Mark Ransom Jul 24 '18 at 22:37
  • That was what i noticed after i changed my code for gifs and i undrstand now why. thank for your answers however !! – khalsel Jul 25 '18 at 17:33

1 Answers1

1

Gif is lossless it should not change the pixels, I recently did a little application using LSB method with gif format here is few things you should do:

  • make sure when you encoded right, try replacing the pixel(0,0) then verify if the value is change if not so check the decoding

  • make sure that the gif color is 255

  • you will encounter this later but you should put the original metadata and delay time when assembling the frames

These are the main issues, other than that as I said earlier it is a lossless compression just like png it should not change the pixels so the problem is either in coding/decoding or type of the RGB color.

ilyes hamrouni
  • 148
  • 1
  • 12
  • As i said in the question the coding and decoding code is fine since it works for other formats as well as decoding the same coded data before saving . The issue was that the data retrived after saving was different from the ones i saved. I understand now it's because gif pixels are saved in 8bit color palette. However using imageio to read gifs returned an rgb array list (kinda like for png for example) which was what threw me off – khalsel Jul 25 '18 at 17:23
  • Yes. glad you solved your problem! if this answer helped please thumbs up. – ilyes hamrouni Jul 26 '18 at 05:11