MATLAB: I am trying to divide a RGB image into 4*4 block.below program is not running.

digital image processingimage processingImage Processing Toolbox

the program is
function pd_repmt=repmat(n,d,k)
img=imread('F:\Images.jpg', 'jpg');
s=size(img);
%block calculation
n=4; %block size
bs=[n n n];
nb=s./bs;
a_bl=mat2cell(img,repmat(bs(1),1,nb(1)),repmat(bs(2),1,nb(2)));
celldisp(a_bl);
pd_repmt=a_bl;
end
it is givving this error
Maximum recursion limit of 500 reached. Use
set(0,'RecursionLimit',N)
to change the limit. Be aware that exceeding your available stack space can
crash MATLAB and/or your computer.
Error in ==> imformats>find_in_registry
or
Error using ==> rdivide
Matrix dimensions must agree.
Error in ==> repmat at 7
nb=s./bs;
how to correct it??

Best Answer

  • first off i would highly recommend that you do not call your function repmat() as it is already a matlab function. in the line a_bl= matcell() is the repmat that you're calling in the line the same repmat function that it resides? At this point it looks like its a call within a call within a call within a call within a call. Without running the function, it looks to be never ending loop.
    However, put a breakpoint at line 7. See what the dimensions are.