How to superimpose an matrix image into the center of a zero matrix (MATLAB CODE)?

The given image is 211 x 350 and there is a zeros matrix of size 512 x 512. The goal is to superimpose the image in the middle of the zero matrix. Then plot the squared image.
I don't know how to do this part, looking for some help.
Thank you.

 Accepted Answer

z = zeros(14);
b = randi(100,5,8);
sz = size(z);
sb = size(b);
bb = floor((sz - sb)/2)+1;
z(bb(1)+(0:sb(1)-1),bb(2)+(0:sb(2)-1)) = b;

More Answers (1)

Just figure out the starting and ending rows and columns through simple algebra, and do
z(row1:row2, col1:col2) = givenMatrix;
For a start,
row1 = round(256 - 211/2)
I imagine you can figure out the rest, i.e. row2=row1+211-1, etc.

2 Comments

Hi, I'm having a similar issue, however, I don't follow what you're saying exactly. Can you provide more code and reasoning rather than "etc."?
If Andrei's code is too cryptic for you to follow, then let me know. Otherwise it's basically the same thing I said.

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!