필터 지우기
필터 지우기

Embed a secret information into the color image and decode.

조회 수: 3 (최근 30일)
Soomin Lee
Soomin Lee 2022년 1월 13일
댓글: Walter Roberson 2022년 1월 13일
%% 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