Reputation: 3529
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.
Right now I'm creating a bigger matrix of zeroes and pasting the elements (RGB) of the image into it. 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)
Upvotes: 1
Views: 1727
Reputation: 20165
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. imshow
(or image
or imagesc
) can operate with all double data, but they expect it $\in [0,1]$ rather than $\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. If it isn't uint8, then adjust the zeros
command accordingly.
Upvotes: 1