I have made a steganography algorithm in matlab to hide colored image inside another colored image. The probelm is the extracted image isn't same as the original secret image.
The idea of algorithm is taking the pixel from secret image and split it into 4 groups of 2 bits, then put each 2 bits instead of the least significant 2 bits of cover pixel. This is the code below:
clear;
clc;
cover = imread('colored.jpg');
secret = imread('c4.png');
row = size(secret,1);
col = size(secret,2);
col = col -mod(col, 4);
if size(cover, 1) < row*4 || size(cover, 2) < col*4
error('Cover image is too small to hide the hidden image.');
end
disp(size(secret));
for i=1:row
for j=1:4:col
for k=1:3
sbyte = secret(i,j,k);
sbyte = dec2bin(sbyte, 8);
start=1;
for l=j:j+3
cbyte = cover(i,l,k);
cbyte = dec2bin(cbyte, 8);
seg = sbyte(start:start+1);
cbyte(end-1:end) = seg;
cbyte = bin2dec(cbyte);
cover(i,l,k) = cbyte;
start = start+2;
end
end
end
end
imwrite(cover, 'stego_image.png');
disp('----------');
hidden = zeros(size(secret));
stego = imread('stego_image.png');
for i=1:row
for j=1:4:col
for k=1:3
sbyte = '';
for l=j:j+3
cbyte = stego(i,l,k);
cbyte = dec2bin(cbyte, 8);
sbyte = strcat(sbyte, cbyte(end-1:end));
end
hidden(i,j,k) = bin2dec(sbyte);
end
end
end
disp(size(hidden));
hidden = uint8(hidden) .* secret;
imshow(hidden);
The output should be the same as origianl secret image but I got: hidden