converting a cell array into numeric arrays
Show older comments
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});
Accepted Answer
More Answers (1)
Walter Roberson
on 9 Dec 2011
0 votes
Copied from the original thread:
You are trying to apply imhist() to a (subsection of) a truecolor image (which is thus a 3D matrix). imhist() is only for grayscale images. You should convert your whole image to grayscale before you break it up in to blocks; or you should convert each block to grayscale and imhist that as you go; or you should imhist() each of the three color planes separately.
4 Comments
yasmine
on 9 Dec 2011
yasmine
on 9 Dec 2011
Walter Roberson
on 9 Dec 2011
You would only convert an array of cells with cell2mat. e.g., to take a 2 x 3 cell array and unpack it back to (say) the original 37 x 19 numeric array. cell2mat should seldom be used on a single element of a cell array: to convert a single element of a cell array to numeric form, just use {} indices to reference the cell.
I think you should probably be looking in to blockproc() or blkproc() instead of worrying about mat2cell and cell2mat .
yasmine
on 9 Dec 2011
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!