フィルターのクリア

I am getting wrong result while extracting the text

1 回表示 (過去 30 日間)
Ramya
Ramya 2023 年 6 月 6 日
移動済み: Cris LaPierre 2023 年 6 月 26 日
%texthide
c = imread('Ramya.jpg');
message = 'Ramyashree'
message = strtrim(message);
m = length(message) * 8;
AsciiCode = uint8(message);
binaryString = transpose(dec2bin(AsciiCode,8));
binaryString = binaryString(:);
N = length(binaryString);
b = zeros(N,1); %b is a vector of bits
for k = 1:N
if(binaryString(k) == '1')
b(k) = 1;
else
b(k) = 0;
end
end
s = c;
height = size(c,1);
width = size(c,2);
k = 1;
for i = 1 : height
for j = 1 : width
LSB = mod(double(c(i,j)), 2);
if (k>m || LSB == b(k))
s(i,j) = c(i,j);
else
if(LSB == 1)
s(i,j) = c(i,j) - 1;
else
s(i,j) = c(i,j) + 1;
end
k = k + 1;
end
end
end
imwrite(s, 'Ramya_hiddenmsgimage.jpg');
%extract.m
s = imread('Ramya_hiddenmsgimage.jpg');
height = size(s,1);
width = size(s,2);
%For this example the max size is 100 bytes, or 800 bits, (bytes * = bits
m = 800;
k = 1;
for i = 1 : height
for j = 1 : width
if (k <= m)
b(k) = mod(double(s(i,j)),2);
k = k + 1;
end
end
end
binaryVector = b;
binValues = [ 128 64 32 16 8 4 2 1 ];
binaryVector = binaryVector(:);
if mod(length(binaryVector),8) ~= 0
error('Length of binary vector must be a multiple of 8.');
end
binMatrix = reshape(binaryVector,8,100);
display(binMatrix);
textString = char(binValues*binMatrix);
disp(textString);
Output is:À òꪪªªªÿÿ° ÿÿÕRÿÿ÷Ô ` Àyÿá?ÿÀ *?ÿ½ÒÅJ ÿáØ 1þ
  2 件のコメント
Chirag Sarda
Chirag Sarda 2023 年 6 月 22 日
Can you plese descibe what result you were expecting?
Jan
Jan 2023 年 6 月 25 日
N = length(binaryString);
b = zeros(N,1); %b is a vector of bits
for k = 1:N
if(binaryString(k) == '1')
b(k) = 1;
else
b(k) = 0;
end
end
% Simplification:
b = (binaryString == '1');

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

採用された回答

DGM
DGM 2023 年 6 月 25 日
移動済み: Cris LaPierre 2023 年 6 月 26 日
You're writing to non-consecutive pixels based on their original values and the values of the embedded message. When you read the marked image, you're reading a fixed number of consecutive pixels with no knowledge of which pixels were altered or what the original values were (either the image or the message).
% inputs
testfilename = 'test.png';
cleanpict = imread('cameraman.tif'); % you're presuming that the input is single-channel
message = 'Potato';
% simplify things for testing
cleanpict = cleanpict(1,:);
% convert message to a logical column vector (binary representation at 8b/char)
message = strtrim(message);
b = dec2bin(message,8) == '1'; % convert the whole thing first; don't need to cast uint8
b = reshape(b.',[],1); % then do all the reshaping
m = numel(b); % this just seems safer
markedpict = cleanpict;
height = size(cleanpict,1);
width = size(cleanpict,2);
k = 1;
idx = []; % just for testing
for i = 1 : height
for j = 1 : width
LSB = mod(double(cleanpict(i,j)), 2);
if (k>m || LSB == b(k))
% skip if remainder matches message
markedpict(i,j) = cleanpict(i,j);
else
% if remainder differs from message
if(LSB == 1)
% if odd, make even
markedpict(i,j) = cleanpict(i,j) - 1;
else
% if even, make odd
markedpict(i,j) = cleanpict(i,j) + 1;
end
k = k + 1;
idx = [idx; j]; % keep track of which indices are altered
end
end
end
imwrite(markedpict, testfilename);
% the indices that are altered are not consecutive
idx.'
ans = 1×48
2 3 4 5 7 9 12 17 18 19 20 23 28 30 34 35 36 37 38 42 45 47 49 51 52 53 61 62 63 64
% demonstrate that the payload can be recovered
b = mod(markedpict(idx),2); % with knowledge of altered indices
key = '01';
b = reshape(key(b+1),8,[]).'; % convert to char representation of binary
b = char(bin2dec(b).') % convert to numeric -> char
b = 'Potato'
Also, there's no reason to assume that any such watermarking would survive being written to a JPG anyway.
  1 件のコメント
Ramya
Ramya 2023 年 6 月 26 日
移動済み: Cris LaPierre 2023 年 6 月 26 日
thank you so much

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEncryption / Cryptography についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by