why this code is not working *(steganography)

11 ビュー (過去 30 日間)
ahmad nasser
ahmad nasser 2015 年 8 月 30 日
回答済み: Walter Roberson 2015 年 8 月 30 日
function [Eslam] = stegancoder(img,msg,enc_key)
msgtype = ischar(msg);
if msgtype == 1
msg_tmp = double(msg);
msg_D = num2str(length(msg_tmp));
msg_length = length(msg_D);
c = 0;
if msg_length< 7
P_text = 7 - msg_length;
for c = 1:P_text
msg_D = horzcat('0',msg_D);
end
msg_head = horzcat('t',msg_D);
msg_tmp_head = horzcat(msg_head,msg_tmp);
end
else
msg = im2uint8(msg);
msg_tmp = rgb2gray(msg);
[H_M1,H_N1] = size(msg_tmp);
H_M = num2str(H_M1);
H_N = num2str(H_N1);
D_M = length(H_M);
D_N = length(H_N);
P_M = 0; P_N = 0;
c = 0;
if D_M < 4
P_M = 4 - D_M;
for c = 1:P_M
H_M = horzcat('0',H_M);
end
end
c = 0;
if D_N < 4
P_N = 4 - D_N;
for c = 1:P_N
H_N = horzcat('0',H_N);
end
end
msg_head = horzcat(H_M,H_N);
msg_tmp_head = msg_head;
b = 0; k = H_M1;
for b = 1:k
msg_tmp_head = horzcat(msg_tmp_head,msg_tmp(b,:));
end
end
msg_enc = bitxor(uint8(msg_tmp_head),uint8(enc_key));
msg_enc_set = dec2bin(msg_enc, 8);
img_good =double(img);
img_prep = im2uint8(img_good);
redm = 1; greenm = 1; bluem = 1;
redn = 1; greenn = 1; bluen = 1;
[maxM,maxN] = size(img_prep);
c = 0;
run_time = length(msg_enc_set);
for c = 1:run_time;
tmp_code = msg_enc_set(c,:);
if str2double(tmp_code(1)) == 0
img_prep(redm,redn,1) = bitand(img_prep(redm,redn,1),uint8(254));
else
img_prep(redm,redn,1) = bitor(img_prep(redm,redn,1),uint8(1));
end
redm = redm + 1;
if redm>maxM
redn = redn + 1;
redm = 1;
end
if str2double(tmp_code(2)) == 0
img_prep(greenm,greenn,2) = bitand(img_prep(greenm,greenn,2),uint8(254));
else
img_prep(greenm,greenn,2) = bitor(img_prep(greenm,greenn,2),uint8(1));
end
greenm = greenm + 1;
if greenm>maxM
greenn = greenn + 1;
greenm = 1;
end
if str2double(tmp_code(3)) == 0
img_prep(bluem,bluen,3) = bitand(img_prep(bluem,bluen,3),uint8(254));
else
img_prep(bluem,bluen,3) = bitor(img_prep(bluem,bluen,3),uint8(1));
end
bluem = bluem + 1;
if bluem>maxM
bluen = bluen + 1;
bluem = 1;
end
if str2double(tmp_code(4)) == 0
img_prep(bluem,bluen,3) = bitand(img_prep(bluem,bluen,3),uint8(254));
else
img_prep(bluem,bluen,3) = bitor(img_prep(bluem,bluen,3),uint8(1));
end
bluem = bluem + 1;
if bluem>maxM
bluen = bluen + 1;
bluem = 1;
end
if str2double(tmp_code(5)) == 0
img_prep(greenm,greenn,2) = bitand(img_prep(greenm,greenn,2),uint8(254));
else
img_prep(greenm,greenn,2) = bitor(img_prep(greenm,greenn,2),uint8(1));
end
greenm = greenm + 1;
if greenm>maxM
greenn = greenn + 1;
greenm = 1;
end
if str2double(tmp_code(6)) == 0
img_prep(redm,redn,1) = bitand(img_prep(redm,redn,1),uint8(254));
else
img_prep(redm,redn,1) = bitor(img_prep(redm,redn,1),uint8(1));
end
redm = redm + 1;
if redm>maxM
redn = redn + 1;
redm = 1;
end
if str2double(tmp_code(7)) == 0
img_prep(redm,redn,1) = bitand(img_prep(redm,redn,1),uint8(254));
else
img_prep(redm,redn,1) = bitor(img_prep(redm,redn,1),uint8(1));
end
redm = redm + 1;
if redm>maxM
redn = redn + 1;
redm = 1;
end
if str2double(tmp_code(8)) == 0
img_prep(greenm,greenn,2) = bitand(img_prep(greenm,greenn,2),uint8(254));
else
img_prep(greenm,greenn,2) = bitor(img_prep(greenm,greenn,2),uint8(1));
end
greenm = greenm + 1;
if greenm>maxM
greenn = greenn + 1;
greenm = 1;
end
Eslam = img_prep;
end
  2 件のコメント
Geoff Hayes
Geoff Hayes 2015 年 8 月 30 日
ahmad - please elaborate on what you mean by why this code is not working. What are you expecting it to do that it isn't? Are you observing any errors with your input image, message, and key? Please include an example of your image (greyscale or rob), message, and key.
ahmad nasser
ahmad nasser 2015 年 8 月 30 日
when i enter any image to use it as a cover image .by writing x=stegancoder('IMG_4675.JPG','ahmad',42) it gives me this message as an error
??? Attempted to access img_prep(1,1,2); index out of bounds because size(img_prep)=[1,12,1].
Error in ==> stegancoder at 87 img_prep(greenm,greenn,2) = bitor(img_prep(greenm,greenn,2),uint8(1));

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2015 年 8 月 30 日
This link will allow you to find out why your code is not working: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 8 月 30 日
You are passing in the name of an image, but you never imread() the image, so the array you are processing as "img" is the string that is the file name rather than being the file content.

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by