image in image using hiding

8 views (last 30 days)
elma ozge
elma ozge on 22 Jan 2022
Edited: elma ozge on 24 Jan 2022
what we can do?
  1 Comment
DGM
DGM on 22 Jan 2022
Edited: DGM on 22 Jan 2022
There are some examples on the File Exchange
And lots of threads on LSB encoding on the forum
If you're trying to cram a large 3-channel image into a single bitplane of a smaller 1-channel image, you're going to have to decide how much data you want to lose and how you want to lose it. Even after resizing the host image, you're still trying to fit 4.7E6 bits of data into 1.2E6 bits. You can reduce the size of the payload by reducing its geometry, or bits per sample. You can also convert it to an indexed image, but the question asks about embedding RGB content, so I don't know that's acceptable.
There's also the option to use more than the least-significant bit plane, but that would rapidly become visually noticeable. Certainly, occupying the 5 least-significant bit planes with payload would be more than obvious.
It's also worth noting that you're not maintaining the aspect ratio of the host image when you resize it, which is kind of a dead giveaway that the image has been modified. Use NaN in the geometry specification to specify a slack dimension.

Sign in to comment.

Accepted Answer

DGM
DGM on 22 Jan 2022
Edited: DGM on 22 Jan 2022
Here.
You either need a much larger host image, or you need to reduce the payload size. The payload can be reduced by reducing its spatial resolution or its color resolution. This example does both.
% prepare host and payload images
Hpict = imread('cameraman.tif');
Hpict = imresize(Hpict,[550 NaN]);
Ppict = imread('peppers.png');
Ppict = imresize(Ppict,[256 NaN]);
payloadsize = size(Ppict);
hostsize = size(Hpict);
if prod(payloadsize)>prod(hostsize(1:2))
% assuming host is I and payload is RGB
error('host is too small to contain payload in 1 bitplane')
end
map = [hsv(6);1 1 1; 0 0 0];
Ppict = ind2rgb(rgb2ind(Ppict,map),map); % each channel is binarized
imshow(Ppict)
% vectorize payload, insert into host at LSB, write
Ppict = logical(Ppict(:));
bitplane = 1;
outputname = 'hppict.png';
Hlsb = bitget(Hpict,bitplane);
Hlsb(1:numel(Ppict)) = Ppict;
HPpict = bitset(Hpict,bitplane,Hlsb); % host with payload
imwrite(HPpict,outputname)
figure
imshow(HPpict)
% read image, extract payload, rectify
HPpict = imread(outputname);
PRpict = bitget(HPpict,bitplane);
PRpict = reshape(PRpict(1:prod(payloadsize)),payloadsize)*255;
figure
imshow(PRpict);
Note that in order for the payload to be rectified after extraction, its geometry needs to be known. In this example, I assume it's known. If it's not known, then it can be guessed from the factors of the vector length. Otherwise, the size vector itself can be embedded in the host along with the payload.
  5 Comments
DGM
DGM on 24 Jan 2022
Edited: DGM on 24 Jan 2022
The above code only supports the use of one bitplane at a time, as the closing statement intimates. It depends what you mean by "hide Ppict in Hpict without resizing". The above example demonstrates that it is possible to embed Ppict in Hpict without downscaling Ppict -- so long as Hpict can be upscaled to accomodate. If you don't want to upscale Hpict, then Ppict simply will not fit, regardless of how many bitplanes you use. The smallest single-channel image which can contain Ppict would be 768x768. At that point, there wouldn't be any of the host image left.
This will accept an arbitrary vector of bitplanes to use. They will be filled in the order specified. Obviously, the values in the 'bitplanes' vector must be unique. The host image is upscaled only enough to make the payload fit in the specified bitplanes.
Note that all of these examples vectorize the payload, and so payload fitment isn't strictly dependent on the interaction between host and payload geometries. Fitment is dependent only the image area (and the number of bitplanes in this case).
% parameters
bitplane = [1 2];
outputname = 'hppict.png';
% prepare host and payload images
Hpict = imread('cameraman.tif');
Ppict = imread('peppers.png');
payloadsize = size(Ppict);
hostsize = size(Hpict);
newh = ceil(hostsize(1) * sqrt((prod(payloadsize)*8+48)/(prod(hostsize(1:2))*numel(bitplane))))
newh = 1537
if newh>hostsize(1)
Hpict = imresize(Hpict,[newh NaN]);
hostsize = size(Hpict);
end
% convert size and data to binary, vectorize
% insert into host at LSB, write
sizevec = reshape(dec2bin(uint16(payloadsize),16).',[],1)=='1';
Ppict = dec2bin(Ppict,8).' == '1';
Ppict = [sizevec; Ppict(:)]; % first 48 bits are size vector
Hlsb = zeros([hostsize(1:2) numel(bitplane)],'uint8');
for p = 1:numel(bitplane)
Hlsb(:,:,p) = bitget(Hpict,bitplane(p));
end
Hlsb(1:numel(Ppict)) = Ppict;
HPpict = Hpict;
for p = 1:numel(bitplane)
HPpict = bitset(HPpict,bitplane(p),Hlsb(:,:,p)); % host with payload
end
imwrite(HPpict,outputname)
% read image, extract payload, rectify
HPpict = imread(outputname);
HPlsb = zeros([hostsize(1:2) numel(bitplane)],'uint8');
for p = 1:numel(bitplane)
HPlsb(:,:,p) = bitget(HPpict,bitplane(p));
end
payloadsize = bin2dec(num2str(reshape(HPlsb(1:48),16,3).')).' % extract size vector
payloadsize = 1×3
384 512 3
PRpict = reshape(HPlsb(49:prod(payloadsize)*8+48),8,[]).';
PRpict = uint8(reshape(bin2dec(num2str(PRpict)),payloadsize));
imshow(PRpict);

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 22 Jan 2022
I'm attaching an example of hiding a gray scale image in a gray scale image. It should be no problem for you to adapt it to use one or both as RGB images.
  5 Comments
yanqi liu
yanqi liu on 24 Jan 2022
yes,sir,may be use
if numberOfColorChannels > 1
% If it's color, extract the red channel.
hiddenImage = [hiddenImage(:,:,1) hiddenImage(:,:,2) hiddenImage(:,:,3)];
end
to make the matrix into 2 dimension
Image Analyst
Image Analyst on 24 Jan 2022
Yes, you can do what Yanqi said. Just make sure you have enough pixels to do the hiding. This means that you need to have at least 8 times the number of pixels in the red, green, and blue channels all summed together. So if your RGB image is 256x256x3 = 196,608 pixels, then you'll need to have a gray scale image of at least 196,608*8 = 1,572,864 gray scale pixels.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!