如何在图像中封装一些文本信息并使用MATLAB解压缩? [英] How do I encapsulate some text information in an image and extract it using MATLAB?

查看:145
本文介绍了如何在图像中封装一些文本信息并使用MATLAB解压缩?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  new_img = convert(img,text); 
(img,text)= convert_back(new_img);有人可以用MATALB的内置图像说明吗?





解决方案

我相信你正在寻找 steganography 。您可以从 LSB隐写术的MATLAB实施开始。



进行LSB隐写术的一种简单方法是采用无损压缩图像并设置每个分量(R,G,B)的LSB。然后,对于 m x n 图像,您将获得3mn 位来存储信息。由于您修改LSB,因此不会



更新



所以我决定编写一个小,低效但示范的例子:

 函数LSBStega 
%% //图像和文本
I = imread( 'coins.png');
text ='Hello World etc';
assert(numel(I)> numel(text)* 8,'像素数不足');

%% //编码
%//结束字符表示隐藏文本的结尾
end_char ='。';
%//追加
text = [text end_char];
%//将每个字符转换为具有至少8位的二进制形式
%//因为二进制表示
%//将每个字符存储在二进制中行和(:)操作
%//通过列向量化矩阵。
b =转置(dec2bin(text,8));
%//查找哪些位应设置为1或0
ind_0 = find(b =='0');
ind_1 = find(b =='1');
%//将适当的位设置为1和0,并单独休息
I(ind_0)= bitset(I(ind_0),1,0);
I(ind_1)= bitset(I(ind_1),1,1);

%% //更快的解码
text_back = [];
for i = 1:8:numel(I)
%//从图像中的一组8个字节中提取LSB
C = bitget(I(i:i + 7) ,1);
%//从二进制转换为十进制
C = bin2dec(num2str(C));
%//检查是否是结束字符;如果没有,则存储
如果(C == end_char)
break;
else
text_back(end + 1)= C;
end
end
%//转换为文本
text_back = char(text_back);

%% //显示
子图(1,2,1);
title('Original');
imshow(imread('coins.png'));
子图(1,2,2);
标题('Steganography Result');
imshow(I);
disp(text_back);
end


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

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

解决方案

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

这篇关于如何在图像中封装一些文本信息并使用MATLAB解压缩?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆