2017-06-07 23 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