what we can do?

1 comentario

DGM
DGM el 22 de En. de 2022
Editada: DGM el 22 de En. de 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.

Iniciar sesión para comentar.

 Respuesta aceptada

DGM
DGM el 22 de En. de 2022
Editada: DGM el 22 de En. de 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 comentarios

elma ozge
elma ozge el 23 de En. de 2022
Editada: elma ozge el 23 de En. de 2022
Thanks, Could you please tell me about this two lines of code and why we should use that?
map = [hsv(6);1 1 1; 0 0 0];
Ppict = ind2rgb(rgb2ind(Ppict,map),map);
How we can use peppers without any artifact and same as orginal peppers?
Ppict = imread('peppers.png');
figure;
imshow(Ppict);
DGM
DGM el 23 de En. de 2022
Editada: DGM el 24 de En. de 2022
Those two lines reduce the color by converting the image from 8 bits per channel (24b) to 1 bit per channel. This reduces the area required to store the payload.
If you want to store the whole, unaltered image, you'll need the host image to be much larger. This example embeds the entire RGB image, without resizing or reducing the color. As suggested in the prior example, this example prefixes the embedded payload with a vector describing the original payload geometry. This way, the geometry doesn't have to be guessed or known beforehand.
% 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))))
newh = 2173
Hpict = imresize(Hpict,[newh NaN]);
% 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
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)
% read image, extract payload, rectify
HPpict = imread(outputname);
PRpict = bitget(HPpict,bitplane);
payloadsize = bin2dec(num2str(reshape(PRpict(1:48),16,3).')).' % extract size vector
payloadsize = 1×3
384 512 3
PRpict = reshape(PRpict(49:prod(payloadsize)*8+48),8,[]).';
PRpict = uint8(reshape(bin2dec(num2str(PRpict)),payloadsize));
imshow(PRpict); % show the recovered image
The new host image size is about 2200x2200. The host image can be no smaller without either:
  • reducing the geometry of the payload
  • reducing the color depth of the payload
  • using multiple bitplanes (and increasing the visibility of the payload)
elma ozge
elma ozge el 24 de En. de 2022
Thanks. I tried two use two bitplanes (1 and 2) but I couldn't extract Ppict from two bitplanes.
Actually I want to hide Ppict in Hpict without any resizing but use two bitplanes is a good idea. Do you have any opinion for do that?
DGM
DGM el 24 de En. de 2022
Editada: DGM el 24 de En. de 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);
elma ozge
elma ozge el 24 de En. de 2022
Thanks.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 22 de En. de 2022

0 votos

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 comentarios

elma ozge
elma ozge el 23 de En. de 2022
I saw it before but I want to hide a small 3-channel image in larger 1-channel image and restore that.
Do you have any adaptation for this goal?
My code does that. Just take it one step at a time. Split your images into 3 parts
[rCover, gCover, bCover] = imsplit(rgbCover);
[rHidden, gHidden, bHidden] = imsplit(rgbWatermark);
Now use my code 3 times.
Hide rHidden in rCover, hide gHidden in gCover, and hide bHidden in bCover. Then recombine the separate color channels into one RGB image using cat():
rStego = cat(3, rCover, gCover, bCover);
I'm pretty sure it's not beyond your capabilities!
elma ozge
elma ozge el 23 de En. de 2022
The main problem is that I have gray scale image for Cover not RGB image and I want to hide RGB image in grayscale image, as you can see in title.
Do you have any opinion?
yanqi liu
yanqi liu el 24 de En. de 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 el 24 de En. de 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.

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 22 de En. de 2022

Editada:

el 24 de En. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by