converting a cell array into numeric arrays
이전 댓글 표시
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});
채택된 답변
추가 답변 (1개)
Walter Roberson
2011년 12월 9일
0 개 추천
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
yasmine
2011년 12월 9일
yasmine
2011년 12월 9일
Walter Roberson
2011년 12월 9일
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
2011년 12월 9일
카테고리
도움말 센터 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!