How to paste or add an image of smaller size to a blank frame of bigger size

How to paste or add an image to reduced size into a blank frame of a bigger size. By example the blank frame can be 300 X 300 and the other image can be resized 50 X 75 and pasted to the blank frame.

 Réponse acceptée

Thorsten
Thorsten le 12 Fév 2013
Modifié(e) : Thorsten le 12 Fév 2013
I = imread('cameraman.tif');
I = im2double(imresize(I, 0.2));
E = ones(300);
E([1:size(I,1)] + 40, [1:size(I,2)] + 120) = I;
imshow(E)

6 commentaires

Works great. Can you explain E([1:size(I,1)] + 40, [1:size(I,2)] + 120) = I;? I will accept the answer anyway.
Great answer. Very simple and very clear and very short. Well done.
Inserting the matrix works by defining the indices ind1 and ind2 in the larger matrix E where the smaller matrix I should be inserted:
E(ind1, ind2) = I;
How to figure out the indices ind1 and ind2? First and foremost the number of elements in ind1 has to equal the number of rows in I, and the number of elements in ind2 has to equal the number of columns. This can be achieved by
ind1 = 1:size(I, 1);
ind2 = 1:size(I, 2);
The command
E(ind1, ind2) = I;
would then insert I at the top left corner of E.
If we want to insert I somewhere else, we add the desired offset to ind1 and ind2:
E(ind1 + 40, ind2 + 120) = I;
If you do not need ind1 nor ind2 for further computation, you can lump everything together in a one-liner:
E([1:size(I,1)] + 40, [1:size(I,2)] + 120) = I;
Great explanation. I did modify the codes to accomplish more stuff.
You seem pretty good. Can you do the following? Create a triangular image with height of 200 pixels and the base of 200 pixels and color the image in any two colors.
Did you see my last request? Create a triangular image with height of 200 pixels and the base of 200 pixels and color the image in any two colors.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by