Clear Filters
Clear Filters

In the extract line I'm having a problem( extracted_text_image) Any Help? I need help

1 view (last 30 days)
%% Return the binary data to text
if mod(length(extracted_bin_message),8) ~= 0
error('Length of binary vector must be a multiple of 8.');
end
binMatrix = reshape(extracted_bin_message,8,[]);
textString = binValues*binMatrix;
extracted_text = char(textString);
isequal(extracted_text, text)
extracted_text_image = uint8(reshape(textString,size(All_img_Malicious{i},1),size(All_img_Malicious{i},2)));
figure, imshow(extracted_text_image)
isequal(text_image, extracted_text_image)
imwrite(uint8(extracted_text_image),[pwd,'\Datasets\Multi_K_M\K_M_0.4_50\Img_Kind\','Img_Kind_hbpp_',num2str(hbit_rate),'_',num2str(i),'.tiff']);

Answers (1)

Simar
Simar on 6 May 2024
Hi f alqhtani,
As per my understanding this is a project on digital image steganography, focusing on embedding a text message into an image and subsequently extracting it to its original form. The error in the line involving extracted_text_image might be due to several reasons. Upon examining the code, here are some suggestions to consider for resolving the issue:
  • Incorrect Dimensions in Reshape: The error might be due to dimensions specified in the reshape function not matching the total number of elements in textString. Ensure product of dimensions to reshape matches the length of textString.
  • Data Type Mismatch: Ensure correct handling of data types."Char" function changes numeric ASCII values into characters. For reshaping back into an image, conversion to uint8 is used. This step should work well but verify that operations leading to textString generate integer ASCII values.
  • Matrix Multiplication Issue: Verify that "textString = binValues*binMatrix" correctly performs matrix multiplication for binary to decimal conversion. Confirm binValues is defined as [128 64 32 16 8 4 2 1] or a similar sequence for the binary format. Additionally, check that this multiplication accurately transforms binary columns into decimal ASCII values.
  • Debugging Steps:
  1. Check the dimensions of All_img_Malicious{i} and ensure they match expected dimensions of textString when reshaped. Use numel(textString) to compare against the product of the intended dimensions.
  2. Ensure that binMatrix is correctly formed and that binValues is correctly defined for binary to decimal conversion.
  3. Inspect intermediate variables (textString, binMatrix, etc.) to ensure they hold the expected values.
Here is a slightly modified version of code with added comments for clarity:
% Ensure binValues is defined correctly
binValues = [128 64 32 16 8 4 2 1];
% Convert binary vector to ASCII values
if mod(length(extracted_bin_message), 8) ~= 0
error('Length of binary vector must be a multiple of 8.');
end
binMatrix = reshape(extracted_bin_message, 8, []);
textString = binValues * binMatrix; % This should be a row vector of ASCII values
extracted_text = char(textString); % Convert ASCII values to characters
% Debug: Check if extracted text matches original text
isequal(extracted_text, text)
% Reshape ASCII values back to image
% Ensure dimensions match those of the original image
if numel(textString) ~= size(All_img_Malicious{i}, 1) * size(All_img_Malicious{i}, 2)
error('Dimension mismatch between textString and target image size.');
end
extracted_text_image = uint8(reshape(textString, size(All_img_Malicious{i}, 1), size(All_img_Malicious{i}, 2)));
% Display and save the image
figure, imshow(extracted_text_image)
isequal(text_image, extracted_text_image)
imwrite(extracted_text_image, [pwd, '\Datasets\Multi_K_M\K_M_0.4_50\Img_Kind\', 'Img_Kind_hbpp_', num2str(hbit_rate), '_', num2str(i), '.tiff']);
Ensure that dimensions of All_img_Malicious{i} are accurate and length of textString matches the expected number of elements. If problem persists, then need to further debug the dimensions and data types of the variables involved.
Please refer to the following documentation links-
  • Char- https://www.mathworks.com/help/matlab/ref/char.html?searchHighlight=char&s_tid=srchtitle_support_results_1_char
  • Numel- https://www.mathworks.com/help/matlab/ref/double.numel.html?searchHighlight=numel&s_tid=srchtitle_support_results_1_numel
Hope this helps!
Best Regards,
Simar

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!