我试图将图像隐藏到另一个图像中。为此,我首先将图像调整为相同的大小。然后拆分R,G和B矩阵以隐藏内容。我成功地将第一张图像隐藏到了其他R,G和B矩阵中。 所以问题是现在我无法将R,B和G连成一张图像,这是我的努力。
Image1=imread('cameraman.tif');
%imshow(Image1);
Image2=imread('saturn.png');
%imshow(Image2);
%scale=[height,width];
%Resized_image=imresize(Image1,[height,width]);
Resized_image = imresize( Image1,[size(Image2,1) size(Image2,2)]);
%imshow(Image2),figure,imshow(Resized_image);
%converting an image into binary form
Temp=Resized_image;
Temp2=Image2;
%Getting red,blue and green matrices.
im_red = Image2;
im_green = Image2;
im_blue = Image2;
im_red(:,:,2) = 0;
im_red(:,:,3) = 0;
[x,y] = size(Temp);
%trying to put 2bits into red
for i=1:x
for j=1:y
bin = bitshift(im_red(i,j),2);
first_2_bits = bitshift(Temp(i,j),6);
oring = bitor(bin,first_2_bits);
Temp2(i,j) = oring;
end
end
%green matrix
im_green(:,:,1) = 0;
im_green(:,:,3) = 0;
[a,b] = size(Temp);
% t1 = a+x;
% t2 = b+y;
for i=1:a
for j=1:b
bin = bitshift(im_green(i,j),2);
first_2_bits = bitshift(Temp(i,j),6);
oring = bitor(bin,first_2_bits);
Temp2(i,j) = oring;
end
end
%Blue matrix
im_blue(:,:,1) = 0;
im_blue(:,:,2) = 0;
[c,d] = size(Temp);
for i=1:c
for j=1:d
bin = bitshift(im_blue(i,j),2);
first_2_bits = bitshift(Temp(i,j),6);
oring = bitor(bin,first_2_bits);
Temp2(i,j) = oring;
end
end
img=cat(3,im_red,im_green,im_blue);
imshow(im_red),figure,imshow(im_green),figure,imshow(im_blue),figure,imshow(img);
所以我得到的错误是不支持连接图像的维度' img'
答案 0 :(得分:0)
连接图像时,每个单独的图像必须具有尺寸1500x1200
,以便RGB图像具有尺寸1500x1200x3
。
一个解决方案是:
img = cat(3,im_red(:,:,1), im_green(:,:,2), im_blue(:,:,3));
另一种选择是:
img = im_red + im_green + im_blue;