How to encode characters of my text message into bytes of an image (Byte Watermarking)

2 ビュー (過去 30 日間)
Fafa Teligence
Fafa Teligence 2020 年 12 月 11 日
編集済み: Sameer 2024 年 9 月 17 日
Hello everyone!
I want to write a code to watermark my image using Byte Watermarking by which I encode each character of my text string into a single byte of my image.
I would be appreciative if anyone can help me.

回答 (1 件)

Sameer
Sameer 2024 年 9 月 17 日
編集済み: Sameer 2024 年 9 月 17 日
Hi
From my understanding, you want to embed a text string into an image by encoding each character of the text into a single byte of the image.
The idea is to replace the least significant byte of the image's pixel data with the "ASCII" values of the characters in the given text. This method allows embedding text into an image without significantly altering its appearance.
Here's how you can implement it:
function watermarked_image = byte_watermarking(original_image, text)
% Read the original image
img = imread(original_image);
% Convert the image to grayscale if it is not already
if size(img, 3) == 3
img = rgb2gray(img);
end
% Convert the text to its ASCII values
ascii_values = uint8(text);
% Ensure the image is large enough to hold the text
[rows, cols] = size(img);
if length(ascii_values) > rows * cols
error('Text is too long to be encoded in the image.');
end
% Flatten the image matrix to a vector for easier processing
img_vector = img(:);
% Embed the ASCII values into the image
img_vector(1:length(ascii_values)) = ascii_values;
% Reshape the vector back to the original image size
watermarked_image = reshape(img_vector, [rows, cols]);
% Display the watermarked image
imshow(watermarked_image);
title('Watermarked Image');
% save the image
imwrite(watermarked_image, 'watermarked_image.png');
end
Hope this helps!

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by