Embed a secret information into the color image and decode.

3 次查看(过去 30 天)
%% embed secret
% Import the base image
Base = imread('peppers.png');
imshow(Base);title('Base Image')
% Import the message image and convert to binary image
Message=imread('secret_spy.jpg');
Msg=imbinarize(rgb2gray(Message));
% Resize the message and base image to same size
Msg=imresize(Msg,size(Base(:,:,1)));
% Select a bit plane and change it to our message signal
New=Base;
New(:,:,1)=bitset(New(:,:,1),1,Msg);
% Save the image file
imshow(New);title('Image with hidden message')
%montage(Base,New);
imwrite(New,'MsgIm.bmp');
clc;
I used this code to embed the secret and now I am trying to decode this.
I used this below but failed. How should I decode it? I can't use predefined function.
%% Decode
% Import the image with hidden image
Im = imread('gray_peppers_secret.png');
% Extract the bitplane of the message signal
MessageImage=bitget(Im(:,:,1),1);
% Visualize the message
imshow(logical(MessageImage));
  3 个评论
Soomin Lee
Soomin Lee 2022-1-13
Oh shoot. Thank you for pointing that out. It was a dumb mistake :/
Is there a way to do this without making the secret image into binary image? I want to keep the color as it is.
Walter Roberson
Walter Roberson 2022-1-13
You have numel(Base) * 1 bits available to encode into.
You have numel(Message) * 8 bits that you need to encode.
So you need to resize(Message) to get Msg such that numel(Msg)*8 == numel(Base)... so numel(Msg) = numel(Base)/8 .
But what resizing factor do you use to accomplish that? You need
imresize(Message, [size(Base,1)/A, size(Base,2)/B])
such that A*B == 8 . But you cannot distribute the 8 equally as A == B == sqrt(8) because sqrt(8) is irrational, and you can be sure that the resulting image will not have exactly the right number of locations.
What are the factors? Well, you can do (1,8) or (2,4) or (4,2) or (8,1) ... are those acceptable ?
Or... you can figure out a way that you do not use every available location to encode the image.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by