Search code examples
matlabpaddingzero

Zero padding in Matlab


I have image, and I want to do up sampling. First of all I need to plug zeros between pixels such that [1,2,3] transforms to [1,0,2,0,3]. Can anyone tell me how to do it without using paddarray and without using for loops?

Thank you in advance!


Solution

  • Something like this?:

    B=zeros(size(img)*2);
    B(1:2:end,1:2:end)=img;
    

    However there are ways of up-sampling in matlab without having the need of doing it by hand, for example interp2