MATLAB Answers

0

add text to photos please check my code, latest_dat​a(i,j,k)=c​andidate_I​mage(i,j,k​)-mod(cand​idate_Imag​e(i,j,k),2​)+M(count,​1);

Asked by ahmad assahab on 22 Nov 2019 at 18:09
Latest activity Commented on by ahmad assahab on 4 Dec 2019 at 9:02
candidate_Image=('apa.jpg'); %load the image
M = 'rahasia.txt'
rahasia=fopen (M,'rb'); %open secret file
[M,L] = fread(rahasia,'ubit1'); %read secret file as bin array
% L is the length of secret file
[n,m]=size(candidate_Image); %n is width, m is height*3
m=m/3;
%m*n is the max size to save secret
if (m*n*3<L)
msg=msgbox('your picture is too small','size error','modal');
pause (1);
if (ishandle (msg))
close (msg);
end
end
latest_data=candidate_Image;
count=1;
for i=1:m %width
for j=1:n %height
for k=1:3 %RGB
latest_data(i,j,k)=candidate_Image(i,j,k)-mod(candidate_Image(i,j,k),2)+M(count,1);
if count==L
break;
end
count=count+1;
end
if count==L
break;
end
end
if (L==count)
break;
end
end
imwrite(latest_data, 'encrypted_Image.jpg', 'bmp');
CC=M;
countl=l;
for i=l:m
for j=l:n
for k=l:3
CC(countl)=latest_data(i,j,k)-candidate_Image(i,j,k);
if countl==L
break
end
countl=countl+l
end
if countl==L
break
end
end
if countl==L
break
end
end

  0 Comments

Sign in to comment.

1 Answer

Answer by Image Analyst
on 22 Nov 2019 at 18:39

What does that way under-commented code do? Is it steganography where you're hiding/encoding text in the image pixels? If so, see my attached example.

  6 Comments

That sets the folder to the folder where the demo images are that ship with MATLAB. You can change it to whatever you want. Replace it with
folder = uigetdir();
or
startingFolder = 'c:/users/ahmad/wherever you want';
folder = uigetdir(startingFolder);
You can save the stego image if you want:
% Get the name of the file that the user wants to save.
% Note, if you're saving an image you can use imsave() instead of uiputfile().
startingFolder = userpath % Or "pwd" or wherever you want.
defaultFileName = fullfile(startingFolder, '*.*');
[baseFileName, folder] = uiputfile(defaultFileName, 'Specify a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
imwrite(stegoImage, fullFileName);
how about coding an affine cipher that hides text to image files?

Sign in to comment.