The output doesn't get the original text back.
    5 views (last 30 days)
  
       Show older comments
    
    Ei Sandar Tun
 on 1 Jan 2021
  
    
    
    
    
    Commented: Ei Sandar Tun
 on 3 Jan 2021
            Hello, I am doing project of image steganography. While extraction the secret file, the output doesn't get the original text back if I use the Text file(*.txt). May I know how to solve it?
% Clear the existing workspace 
clear var; 
% Clear the command window 
clc; 
% Getting the input image 
[rawname, rawpath]= uigetfile (('*.jpg'),'Select Image');
fullname = [rawpath rawname];
%set (handles., 'string', fullname);
input_image = imread(fullname);
imshow(input_image);
%imread('Encrypted6-image.jpg'); 
% Get height and width for traversing through the image 
height = size(input_image, 1); 
width = size(input_image, 2); 
% Number of characters of the hidden text 
chars = 100; 
% Number of bits in the message 
message_length = chars * 8; 
% counter to keep track of number of bits extracted 
counter = 1; 
% Traverse through the image 
for i = 1 : height 
	for j = 1 : width 
		% If more bits remain to be extracted 
		if (counter <= message_length) 
			% Store the LSB of the pixel in extracted_bits 
			extracted_bits(counter, 1) = mod(double(input_image(i, j)), 2); 
			% Increment the counter 
			counter = counter + 1; 
		end
	end
end
% Powers of 2 to get the ASCII value from binary 
binValues = [ 128 64 32 16 8 4 2 1 ]; 
% Get all the bits in 8 columned table 
% Each row is the bits of the character 
% in the hidden text 
binMatrix = reshape(extracted_bits, 8,(message_length/8)); 
% Convert the extracted bits to characters 
% by multiplying with powers of 2 
textString = char(binValues*binMatrix); 
% Print the hidden text 
disp(textString); 
Here is my extracted code and below is the output.

0 Comments
Accepted Answer
  Image Analyst
      
      
 on 1 Jan 2021
        I didn't delve into your code, but I'm attaching a demo of mine.  Perhaps that will help you.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
