clc;
clear variables;
I=imread('input.png');
[rows, columns, numberOfColorChannels] = size(I);
if numberOfColorChannels > 1
I = rgb2gray(I);
end
L=256;
image_hide=I;
message=input('Please enter the message you want to hide: ','s');
len=strlength(message)*8;
ascii_values=uint8(message);
ascii2binary=dec2bin(ascii_values,8);
binary_sequence='';
for i=1:strlength(message)
binary_sequence=append(binary_sequence,ascii2binary(i,:));
end
bitCount=1;
for i=1:rows
for j=1:columns
if bitCount<=len
LSB=mod(I(i,j),2);
a=str2double(binary_sequence(bitCount));
temp=double(xor(LSB,a));
image_hide(i,j)=I(i,j)+temp;
bitCount=bitCount+1;
end
end
end
subplot(1,2,1);
imshow(I);
title('Input Image');
subplot(1,2,2);
imshow(image_hide);
title('Image with Hidden Data');
imwrite(image_hide,'output.png')