简体   繁体   English

Matlab:将RGB图像粘贴到更大的图像中

[英]Matlab: paste RGB image into bigger image

I am trying to read an image and paste it into a bigger image in which I will, later, paste other images (same heights and widths). 我正在尝试读取图像并将其粘贴到更大的图像中,以后再粘贴其他图像(相同的高度和宽度)。 I have to say that I'm not experienced in Matlab so any suggestions are welcome. 我不得不说我没有Matlab的经验,所以欢迎提出任何建议。

Right now I'm creating a bigger matrix of zeroes and pasting the elements (RGB) of the image into it. 现在,我正在创建一个更大的零矩阵,并将图像的元素(RGB)粘贴到其中。 But it is not being displayed as I would want, it shows a mostly-white image: 但是它并没有按照我的意愿显示,而是显示了大部分为白色的图像:

Bigger is the name of the bigger image 更大是更大形象的名称

[im1 map1] = imread('/12937.png');
[height width rgbsize]=size(im1)
bigger=zeros(height+200,width+200,3);
figure('name','original');imshow(im1) %displays my image correctly
bigger(1:height,1:width,:)=im1(:,:,:); 
figure('name','after');imshow(bigger); %displays a mostly white image with dark right and bottom borders (the extra size)

Some of the image functions are sensitive to the data types. 一些图像功能对数据类型敏感。 imread gives you a matrix of type uint8, whereas by default, zeros gives you matrices of type double. imread为您提供了uint8类型的矩阵,而默认情况下, zeros为您提供了double类型的矩阵。 imshow (or image or imagesc ) can operate with all double data, but they expect it $\\in [0,1]$ rather than $\\in [0,255]$. imshow (或imageimagesc )可以对所有double数据进行操作,但他们希望它在[0,1] $中而不是$ \\ in [0,255] $中。

Try this: 尝试这个:

[im1 map1] = imread('/12937.png');
[height width rgbsize]=size(im1)

% note: initialise the data type as well as the size
bigger=zeros(height+200,width+200,3, 'uint8');

figure('name','original');imshow(im1) 
bigger(1:height,1:width,:)=im1(:,:,:); 
figure('name','after');imshow(bigger); 

You can check what type im1 is with the command whos , or looking in the workspace part of the GUI. 您可以使用whos或在GUI的工作区部分中检查im1是什么类型。 If it isn't uint8, then adjust the zeros command accordingly. 如果不是uint8,则相应地调整zeros命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM