【将文本编码为图像灰度级别】以 ASCII 编码并与灰度级别位混合将文本字符串隐藏到图像像素的最低位中,使其不明显研究(Matlab代码实现)

 💥💥💞💞欢迎来到本博客❤️❤️💥💥

🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。

⛳️座右铭:行百里者,半于九十。

📋📋📋本文目录如下:🎁🎁🎁

目录

💥1 概述

📚2 运行结果

🎉3 参考文献

🌈4 Matlab代码实现


💥1 概述

经过文本编码技术的应用,我们可以将文本字符串隐藏在图像像素的最低位中,使其在视觉上不易察觉。

在这个实例中,用户可以输入文本消息,并选择要隐藏消息的图像(这些图像是来自MATLAB附带的演示图像列表)。用户还可以选择要用于编码消息的位平面。首先,将文本消息转换为ASCII代码,然后将其转换为二进制字符串。接着,将被选择的位平面与图像像素相对应,从左上角像素开始,自上而下,自左至右进行分配。

由于文本消息以ASCII编码并与灰度级别位混合,所以在图像上并不容易被察觉到。这样的隐藏技术在隐写术领域中具有重要意义,允许用户在图像中嵌入机密信息,而外观上几乎没有变化。

通过这种方法,可以实现图像与文本之间的隐蔽通信,为信息安全和隐私保护提供了一种隐蔽的手段。然而,需要注意的是,隐写术的应用必须遵循法律和伦理准则,以确保信息的嵌入和提取仅在合法的领域进行。

📚2 运行结果

部分代码:

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\nThe "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\nThe "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 参考文献

文章中一些内容引自网络,会注明出处或引用为参考文献,难免有未尽之处,如有不妥,请随时联系删除。

[1]张健.复杂图像文本提取关键技术与应用研究[D].南开大学,2015.

[2]张姁.基于小波的彩色图像灰度水印算法研究[D].河北工业大学[2023-09-25].DOI:10.7666/d.d049536.

[3]刘勇.二值图像压缩编码算法的若干研究[D].山东大学,2009.DOI:10.7666/d.y1562519.

🌈4 Matlab代码实现

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用Python编写的将图像转换为字符画的程序: ```python from PIL import Image # 定义字符画中所使用的字符集 ascii_char = list("@#&$%*o!;.") # 将256个灰度值映射到70个字符上,灰度值越高,字符密度越小 def get_char(r, g, b, alpha=256): if alpha == 0: return ' ' gray = int(0.2126 * r + 0.7152 * g + 0.0722 * b) unit = (256.0 + 1) / len(ascii_char) return ascii_char[int(gray/unit)] # 加载图像并将其转换为字符画 def convert_image_to_ascii(image_path): im = Image.open(image_path) width, height = im.size # 将图像缩小,以便生成更小的字符画 im = im.resize((int(width*0.5), int(height*0.25))) width, height = im.size # 创建一个空的字符画字符串 ascii_image = '' # 遍历图像中的每个像素,并将其转换为字符 for h in range(height): for w in range(width): ascii_image += get_char(*im.getpixel((w, h))) ascii_image += '\n' return ascii_image # 将字符画保存为文本文件 def save_ascii_image(ascii_image, output_path): with open(output_path, 'w') as f: f.write(ascii_image) # 将图像转换为字符画并将其保存为文本文件 def main(): image_path = 'example.png' output_path = 'example.txt' ascii_image = convert_image_to_ascii(image_path) save_ascii_image(ascii_image, output_path) if __name__ == '__main__': main() ``` 在上述程序中,我们使用Pillow库中的Image类加载图像,并将其缩小到一定大小,以便生成较小的字符画。然后,我们遍历图像中的每个像素,并将其转换为字符。最后,我们将字符画保存为文本文件。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值