MATLAB: Converting a cell array into numeric arrays

digital image processingimage processing

I am dividing images into blocks using mat2cell then i want to convert each block from cell array to a numeric array to make histogram for every block.
I need to make it in a for loop.
so what do you think?
here is my code:
nb(1) = ceil(256/ b(1)); % number of blocks in each dimension

nb(2) = ceil(384/ b(2)); % number of blocks in each dimension
C=mat2cell(images,ones(256/ b(1),1)*b(1),ones(384/ b(2),1)*b(2),3);% dividing the Image into blocks.
%C1=mat2cell(images,repmat(b(1),1,nb(1)), repmat(b(2),1,nb(2)),3);
m=1;
while (m < ((nb(1)*nb(2))+1))
for i=1:nb(1)%256
for j=1:nb(2)%384
[counts(i,j), x(i,j)] = imhist(C{i,j});%error
end
end
end
end
end
it gave me these errors:
??? Error using ==> iptcheckinput Function IMHIST expected its first input, I or X, to be two-dimensional.
Error in ==> imhist>parse_inputs at 281 iptcheckinput(a, {'double','uint8','int8','logical','uint16','int16','single','uint32', 'int32'}, …
Error in ==> imhist at 59 [a, n, isScaled, top, map] = parse_inputs(varargin{:});
Error in ==> fll1 at 26 [counts(i,j), x(i,j)] = imhist(C{i,j});

Best Answer

Just use cellfun with imhist as the function being applied.
As for the two dimensionality, use rgb2gray to convert your rgb image to a gray image so that data are 2-dimensional. Or use a for-loop form 1:3 to apply imhist to each slice of the third dimension.
Related Question