hide numerical values in image

how to hide a matrix into an image and retrieve it.
i used the lsb code from the link
i can hide the data. But while retrieving i'm not able to recover the matrix values. Its coming as empty string values. Even the bitStream values when i convert to double is not coming correctly
How can i do it for numerical values.

 Accepted Answer

Image Analyst
Image Analyst on 23 Feb 2019
See my attached demo where I hide an image in another image and then recover it.

13 Comments

sir i went through your lsb codes, the one with visible watermarking also. But what if i want to store 2 images as same size of cover image
As I told you twice before it is not possible to hide two images the same size as the cover image both into the same lsb.
Consider the top left corner . Suppose it is 10010110 binary . Now suppose the bit for the first image is a 0, then you overwrite the 0 lsb with a 0 giving you 1001011|0 where here the bar is not there but just indicates that the 1001011- will be used from the cover image and that 0 from the first secret image is to be used.
Now suppose that the bit for the second secret image is 1. Now where are you going to put it? The top 7 bits cannot be affected because you are restricting yourself to lsb techniques . If you overwrite the 0 of 1001011|0 with the 1 of the second image then the 0 will not be there to be extracted afterwards .
LSB techniques cannot hide more total bits than the number of lsb bits, which is rows*columns . You are trying to hide rows*columns*2 bits.
I guess maybe you could hide it in the image FILE but not the image, like for example if you made a custom TIFF tag and put the hidden image in that. No one would know it's there when they just do a simple display - you'd have to know that it was there and do special things to pull it out. Similar to an image hidden in the pixels - you have to do special things to pull it out.
Of course I don't know why this is even needed at all. If you want hidden things, then why not just encrypt them using normal encryption methods? True, someone might not know that you're hiding things with steganography like they would with a file encrypted normally, but is that any reason to use a less secure hiding method (I'm pretty sure steganography is much less secure than normal 128 bit encryption)
Sir, do you have any example of how to make a custom TIFF tag and put the hidden image in that.
No I don't. You can study up on the TIFF class in the MATLAB help and perhaps it will have methods there that will allow you to attach/insert a custom tag.
If you want hidden things, then why not just encrypt them using normal encryption methods?
I tried some of the encryption methods available, but i'm not able to encrypt 2 images of same size into one, and retrieve it.
Actually i also want, to do a croping from the stegoImage and still, i should be able to extract both the hidden image.
Sir, i tried the example of tiff using colour image
tagstruct.ImageLength = size(imgdata,1)
tagstruct.ImageWidth = size(imgdata,2)
tagstruct.Photometric = Tiff.Photometric.RGB
tagstruct.BitsPerSample = 8
tagstruct.SamplesPerPixel = 3
tagstruct.RowsPerStrip = 16
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky
tagstruct.Software = 'MATLAB'
its working fine for colour images. please can you help me with the changes i need to make for gray images
Its not RGB, is it Pallette
when i write as below it shows error
tagstruct.Photometric = Tiff.Photometric.Pallette
error
Reference to non-existent field 'Pallette'.
Error in demo_tif_my (line 13)
tagstruct.Photometric = Tiff.Photometric.Pallette
can you help me solve it out
Tiff.Photometric.Palette -- only one l
Note that Palette corresponds to pseudo-color images, where the value you write is not an intensity but is instead a color index. If you change a value that is a color index by 1 bit, you could end up with a visibly very different image, since it is possible for bright yellow and dull red to be right beside each other in a color map.
Grayscale images should have Tiff.Photometric.BlackIsMin . And remember to switch to SamplesPerPixel = 1 for grayscale.
Elysi:
Suppose I somehow hide a complete 768 x 480 grayscale image of The Mona Lisa into a cover image. Now suppose I crop down to one single pixel. Should I expect to be able to recover the complete Mona Lisa from the cropped image? Suppose I had cropped down to two pixels total: should I expect to be able to recover the complete Mona Lisa from the cropped image? Three pixels? What is the minimuma number of of pixels that we can crop down to and expect to recover the complete 768 x 480 Mona Lisa from?
Now suppose I had hidden a complete 768 x 480 grayscale image of The Mona Lisa into a cover image, and then I cropped down to the left half of that. You expect to be able to recover the complete Mona Lisa, so the complete Mona Lisa has to be hidden in the left half of the original. But you could have taken the right half instead and you expect to be able to recover the complete Mona Lisa from that, so a complete copy must be hidden there too. So you have to hide the Mona Lisa twice, once for left and once for right half. But we could have split top/bottom and you expect to be able to recover the complete Mona Lisa from those, so it follows that you have to hide the Mona Lisa four times, once for each quarter. But you could have chosen to crop into thirds, and you expect to be able to recover from those, so you have to hide the complete Mona Lisa nine times.
By extension, it follows that you have to hide a complete copy of the Mona Lisa in every pixel of the output image in order to meet your requirements.
Note that when people read in the TIFF image to crop it, it is rather unlikely that their process will happen to duplicate your custom TIFF tag. And cropping off custom TIFF tags is a valid "crop" attack.
In order to be able to put 2*n bits of information into n bits, you need some kind of compression routine which is able to compress by at least 2:1 .
For example if your cover image is not using lossy compression (that is, you are not storing as jpeg ) then you might be able to do Discrete Cosine (jpeg) compression of the images to be hidden , choosing a quality level that needs fewer than n/2 bits for each of the two images to hide, and embed the coefficients .
Sir @Walter Roberson,
You have asked me exactly what i wanted
"Suppose I somehow hide a complete 768 x 480 grayscale image of The Mona Lisa into a cover image. Now suppose I crop down to one single pixel. Should I expect to be able to recover the complete Mona Lisa from the cropped image?"
Yes, sir i should be able to recover it. I was asking this only, whether there is any method available.
Then as you said
"You expect to be able to recover the complete Mona Lisa, so the complete Mona Lisa has to be hidden in the left half of the original... hide the Mona Lisa four times, once for each quarter"
Sir, i was asking this only, whether there is any method so that i can hide my 2 images in any 2 quarter, and crop from other 2 quarters. Actually cropping from anywhere should not effect it. But is there any method where "i can hide my 2 images in any 2 quarter"
I opted for this tiff method because i didnt get a solution for hiding my 2 images of same size as cover image in the cover image. If any solution for saving it in quarter, it would be very helpful
Then from the tiff method, i did as below.
im = imread('subimage_file.tif');
im(50:100,50:100,:) = 255;
imwrite(im, 'subimage_file.tif');
But when i do then i cannot read the subdirectory images in the tiff image. Any solution for this? Or should i write it the other way using Tiff class then only i can read it?
Elysi, as long as you don't crop off what you stored, you should be able to recover it. That is if you were able to store it. And storing two quarter sized full dynamic range images in a regular image without seeing it is not possible. You might try hiding an 8 bit image in the lower 8 bits of a 16 bit image.
And you'd need to use the tiff class to have any hope of storing a custom tag, but when your attacker reads it in, there is no guarantee that they will save your tag, in fact, probably won't, just like using imwrite() won't. So it would be easy for your attacker to read in, attack, and save back out, and then you would not be able to tell that that image was your forged/attacked image because your custom tiff tag if no longer there.
Thank you Image Analyst and Walter Roberson for your detailed explanation

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!