主要问题:back_img
属于double
类,img1
属于uint8
类。
类double
的显示图像显示1
以上的所有像素为白色像素。
在uint8
类中,当255是白色时,像素范围为[0,255]。
以下代码:back_img(1:src_y, 1:src_x,1:3) = img1(1:src_y, 1:src_x,1:3);
,将uint8
矩阵放在类(类型)double
的矩阵中。
在这种情况下,Matlab规则是将uint8
个元素转换为double
。
当back_img
为double
时,使用imshow(back_img)
,应用像素范围[0,1](0为黑色,1为白色)。
1以上的像素也是白色的。
原始uint8
图像的几乎所有像素都是1或更高,因此在转换为双倍像素之后显示为白色像素。
解决方法:在与img1
(在您的案例中为uint8
的类)相同的类中创建零矩阵。
检查下面的代码示例:
%Prepeare 200x200 image for the example:
img1 = imresize(imread('peppers.png'), [200, 200]);
boundary_x = 600;
boundary_y = 600;
%back_img = zeros(round(boundary_y),round(boundary_x),3);
%back_img = back_img(:,:,:); %Do nothing...
%Create 600x600x3 zeros matrix in smae class of img1 (in case img1 is
%uint8, class of back_img is uint8 instead of double.
back_img = zeros(round(boundary_y),round(boundary_x),3, class(img1));
[src_y, src_x, ~] = size(img1);
back_img(1:src_y, 1:src_x,1:3) = img1(1:src_y, 1:src_x,1:3);
figure; imshow(back_img);
结果:
结果的原代码:
谢谢,但没有解决问题。 – rowana