2
new_img = convert(img, text);
(img, text) = convert_back(new_img);

Can someone illustrate with a built-in image of MATALB?

Jacob
  • 34,255
  • 14
  • 110
  • 165
user198729
  • 61,774
  • 108
  • 250
  • 348

1 Answers1

7

I believe you're looking for steganography. You can start with this MATLAB implementation of LSB steganography.

A simple way of doing LSB steganography is to take an lossless-compressed image and set the LSB of each component (R,G,B). Then for a m x n image you get 3mn bits to store information in. Since you're modifying the LSB, the difference will not be perceivable in the image.

Update

SO I decided to code up a small, inefficient but demonstrative example:

function LSBStega    
        %%// Image and text
        I = imread('coins.png');
        text = 'Hello World etc';
        assert(numel(I) > numel(text)*8,'Insufficient number of pixels');

        %%// Encode
        %// The end character signifies the end of the hidden text
        end_char = '.';
        %// Append it
        text = [text end_char];
        %// Convert each character into binary form with atleast 8 bits
        %// We transpose it before calling (:) since the binary representation
        %// is stores each character in binary per row and the (:) operations
        %// vectorizes the matrix by column.
        b = transpose(dec2bin(text,8));
        %// Find which bits should be set to 1 or 0
        ind_0 = find(b == '0');
        ind_1 = find(b == '1');
        %// Set the appropriate bits to 1 and 0 and leave the rest alone
        I(ind_0) = bitset(I(ind_0),1,0);
        I(ind_1) = bitset(I(ind_1),1,1);

        %%// Faster decode
        text_back = [];        
        for i = 1:8:numel(I)
            %// Extract the LSB from a set of 8 bytes in the image
            C = bitget(I(i:i+7),1);
            %// Convert from binary to decimal
            C = bin2dec(num2str(C));
            %// Check if it's the end character; break if so, store if not
            if(C == end_char) 
                break;
            else
                text_back(end+1) = C;
            end
        end
        %// Convert to text
        text_back = char(text_back);

        %%// Display
        subplot(1,2,1);
        title('Original');
        imshow(imread('coins.png'));
        subplot(1,2,2);
        title('Steganography Result');
        imshow(I);
        disp(text_back);    
end
Jacob
  • 34,255
  • 14
  • 110
  • 165
  • I downloaded that tool and it works like charm,but there are `.p` and `.fig` files,how do they work? – user198729 Apr 25 '10 at 03:46
  • @user198729: Decided to code up a small example. Try it out ;) – Jacob Apr 25 '10 at 04:25
  • Oh,it works!But I can't understand it...Can you put in more comments there? Like `b = dec2bin(text,8)'; %'` and `b = b(:);`? – user198729 Apr 25 '10 at 04:33
  • Haha, sure. This is LSB steganography, but I'm sure there are better methods out there, so good luck! – Jacob Apr 25 '10 at 04:46
  • Sorry,I still don't see how `'; %'` works,I've never used this syntax before,though through testing I see it combines `8` bit to `16` bit array. – user198729 Apr 25 '10 at 04:50
  • What? No, no, no, the `%'` is useless, it just changes the coloring of the code syntax in StackOverflow. The `'` command transposes the matrix! – Jacob Apr 25 '10 at 04:53
  • I changed the code so I'm explicitly using the `transpose` command. – Jacob Apr 25 '10 at 04:56
  • Oops,wonderful,never see `'` can be used as a function before! The other doubt is `b = b(:);`, it looks useless for me,is it? Oops, it's useful,but what's that syntax called? – user198729 Apr 25 '10 at 05:00
  • Yeah it is useless, I wanted to make the vectorization explicit. I'll remove it. – Jacob Apr 25 '10 at 05:02