2017-06-07 24 views
-4

我想尝试从已插入的消息before..but有与说明书波纹管的错误图像中提取消息..这个隐写术提取代码有什么问题?

此代码提取物:

% Read Image Stego 
IS = imread('imagestego.bmp'); 

% Extract RedChannel 
RedChannel = IS(:,:,1); 

% Convert RedChannel to biner 
bitstego = uint8(reshape(dec2bin(RedChannel,8)',1,[]) = '0'); 
nBitstego = length(bitstego); 

% Extraction 
extBits = bitget(RedChannel(1:end),1).'; 
extMessage = char(bin2dec(reshape(int2str(extBits),8,[]).').'); 

,并从提取的代码此错误:

>> latihanextract 
Error: File: latihanextract.m Line: 8 Column: 55 
The expression to the left of the equals sign is not a valid target for an assignment. 

这是嵌入代码之前..它的工作!

coverImage = imread('foto1.jpg'); 
message = 'IMRON'; 

%EMBEDDING 
RedChannel = coverImage(:,:,1); 
GreenChannel = coverImage(:,:,2); 
BlueChannel = coverImage(:,:,3); 
bits = uint8(reshape(dec2bin(message,8)',1,[]) - '0'); 
nBits = length(bits); 
RedChannel(1:nBits) = bitset(RedChannel(1:nBits),1,bits); 
Imageresults = cat(3,RedChannel,GreenChannel,BlueChannel); 
imwrite(Imageresults,'imagestego.bmp'); 

所以有什么问题?

+1

我不知道你在做什么,但是在代码中你有错误而不是'message'你在第8行有'RedChannel' –

+0

@VaheTshitoyan这是因为得到错误的代码试图* *从'RedChannel'中提取**位,而不是**将'message'的位插入到图像中。 – beaker

+0

请包含[mcve]作为文本而不是截图。此外,尝试阅读并理解您的代码,并使用matlab调试器来分析错误发生的原因,即检查变量并检查为什么要求索引超出矩阵尺寸。 – m7913d

回答

6

这是你的问题......

% Read Image Stego 
IS = imread('stegosaurus.bmp'); 

% Extract RedChannel 
RedChannel = IS(:,:,1); 

% Convert RedChannel to binary 
bitstego = uint8(reshape(dec2bin(RedChannel,8)',1,[]) - '0'); 
nBitstego = length(bitstego); 
% the previous 2 lines are actually unnecessary and can be deleted... 
% see explanation in text below 

% Extrication 
extBits = bitget(RedChannel(1:end),1).'; % (1:end) gives you all of the elements 
extMessage = char(bin2dec(reshape(int2str(extBits),8,[]).').') 

你经位的图像的数量,而不是字节数试图循环。 bitstegobitstego中所有字节的二进制表示形式,因此bitstego的长度是RedChannel的8倍。

在这种情况下,使用特殊索引end来获取RedChannel中的元素数量要容易得多。

+0

那么代码错误@breaker在哪里? 我试过写你的代码一样。 –

+0

啊,那是一个错字。如果你看第8行,你会发现我的代码最初有一个'=',其中有一个'-'。 ''是正确的。正如我所说,第12行和第12行甚至都不需要,所以你甚至可以删除它们。 – beaker

+0

请注意,如果图像中像素的数量(行*列)不能被8整除,则最后一行中仍然存在问题。 – beaker