[Encode text into image gray level] Encoded in ASCII and mixed with gray level bits to hide the text string into the lowest bits of image pixels, making it inconspicuous Research (Matlab code implementation)

Welcome to this blog

Advantages of bloggers:Blog content should be as thoughtful and logical as possible for the convenience of readers.

Motto:He who travels a hundred miles is half as good as ninety.

The directory of this article is as follows:

Table of Contents

1 Overview

2 Operation results

3 References

4 Matlab code implementation


1 Overview

Through the application of text encoding technology, we can hide text strings in the lowest bits of image pixels, making them visually imperceptible.

In this instance, the user can enter a text message and select an image to hide the message (these images are from the demo image list that comes with MATLAB). The user can also select the bitplane to be used to encode the message. First, convert the text message to ASCII code and then convert it to a binary string. Next, the selected bit planes are corresponding to the image pixels, starting from the upper left corner pixel, top to bottom, and left to right.

Because the text message is encoded in ASCII and mixed with grayscale bits, it is not easily noticeable on the image. Such hiding techniques are of great significance in the field of steganography, allowing users to embed confidential information in images with little change in appearance.

Through this method, covert communication between images and text can be achieved, providing a covert means for information security and privacy protection. However, it should be noted that the application of steganography must comply with legal and ethical guidelines to ensure that the embedding and extraction of information is only carried out in legal areas.

2 Operation results

Part of the code:

if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Convert it to gray scale by taking only the green channel.
grayCoverImage = grayCoverImage(:, :, 2); % Take green channel.
elseif ~isempty(storedColorMap)
% There's a colormap, so it's an indexed image, not a grayscale image.
% Apply the color map to turn it into an RGB image.
grayCoverImage = ind2rgb(grayCoverImage, storedColorMap);
% Now turn it into a gray scale image.
grayCoverImage = uint8(255 * mat2gray(rgb2gray(grayCoverImage)));
end
[rows, columns, numberOfColorChannels] = size(grayCoverImage); % Update. Only would possibly change, and that's if the original image was RGB or indexed.
% Display the image.
hFig = figure;
subplot(1, 2, 1);
imshow(grayCoverImage, []);
axis on;
caption = sprintf('The Original Grayscale Image\\
The "Cover" Image.');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');

% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')

%================================================== ==============================
% Get the string the user wants to hide:
hiddenString = 'This is your sample hidden string.';
% Ask user for a string.
defaultValue = hiddenString;
titleBar = 'Enter the string you want to hide';
userPrompt = 'Enter the string you want to hide';
caUserInput = inputdlg(userPrompt, titleBar, [1, length(userPrompt) + 75], {num2str(defaultValue)});
if isempty(caUserInput)
% Bail out if they clicked Cancel.

if numberOfColorChannels > 1
% It’s not really gray scale like we expected – it’s color.
% Convert it to gray scale by taking only the green channel.
grayCoverImage = grayCoverImage(:, :, 2); % Take green channel.
elseif ~isempty(storedColorMap)
% There’s a colormap, so it’s an indexed image, not a grayscale image.
% Apply the color map to turn it into an RGB image.
grayCoverImage = ind2rgb(grayCoverImage, storedColorMap);
% Now turn it into a gray scale image.
grayCoverImage = uint8(255 * mat2gray(rgb2gray(grayCoverImage)));
end
[rows, columns, numberOfColorChannels] = size(grayCoverImage); % Update. Only would possibly change, and that’s if the original image was RGB or indexed.
% Display the image.
hFig = figure;
subplot(1, 2, 1);
imshow(grayCoverImage, []);
axis on;
caption = sprintf(‘The Original Grayscale Image\\
The “Cover” Image.’);
title(caption, ‘FontSize’, fontSize, ‘Interpreter’, ‘None’);

% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, ‘Units’, ‘Normalized’, ‘OuterPosition’, [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, ‘Toolbar’, ‘none’, ‘Menu’, ‘none’);
% Give a name to the title bar.
set(gcf, ‘Name’, ‘Demo by ImageAnalyst’, ‘NumberTitle’, ‘Off’)

%================================================== ==============================
% Get the string the user wants to hide:
hiddenString = ‘This is your sample hidden string.’;
% Ask user for a string.
defaultValue = hiddenString;
titleBar = ‘Enter the string you want to hide’;
userPrompt = ‘Enter the string you want to hide’;
caUserInput = inputdlg(userPrompt, titleBar, [1, length(userPrompt) + 75], {num2str(defaultValue)});
if isempty(caUserInput)
% Bail out if they clicked Cancel.

3 References

Some of the content in the article is quoted from the Internet. The source will be indicated or cited as a reference. It is inevitable that there will be some unfinished information. If there is anything inappropriate, please feel free to contact us to delete it.

[1] Zhang Jian. Research on key technologies and applications of complex image text extraction [D]. Nankai University, 2015.

[2] Zhang Huan. Research on grayscale watermarking algorithm for color images based on wavelet[D]. Hebei University of Technology[2023-09-25].DOI:10.7666/d.d049536.

[3] Liu Yong. Several studies on binary image compression coding algorithms [D]. Shandong University, 2009. DOI: 10.7666/d.y1562519.

4 Matlab code implementation

The knowledge points of the article match the official knowledge files, and you can further learn related knowledge. Algorithm skill tree Home page Overview 55238 people are learning the system