Embed a secret information into the color image and decode.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
%% 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 Kommentare
Walter Roberson
am 13 Jan. 2022
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.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Convert Image Type finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!