You can try this function:
function out1 = myresize(in1) %% Sa1habibi@gmail.com %% resize an image to closest power of 2 [m,n] = size(in1); if(rem(m,2)~=0) in1(1,:)=[]; end if(rem(n,2)~=0) in1(:,1)=[]; end [m,n] = size(in1); a = max(m,n); if(log2(a)~=nextpow2(a) || m~=n) s1 = 2^nextpow2(a); n_row = (s1 - m)/2; n_col = (s1 - n)/2; dimension = [n_row,n_col]; out1 = padarray(in1,dimension); end end
eg:
A = ones(2,8); out1 = myresize(A);
first it finds a maximum of rows and columns, then a paddarray matrix in both directions.
source share