i've an image of size 185x256 and i've divided the image into discrete blocks having block rows 16 and block columns 16. when i access the blocks in a loop it says index exceeds matrix dimension...
이전 댓글 표시
the code is as follows:
in the following image it has 11 rows and 16 columns grayImage http://imageshack.us/photo/my-images/17/tanklb.jpg/
grayImage=rgb2gray(Imread('tank.jpg'));
whos grayImage
[rows columns numberOfBands]=size(grayImage);
blockSizeR = 16;% Rows in block.
blockSizeC = 16; % Columns in block.
wholeBlockRows = floor(rows / blockSizeR);
wholeBlockCols = floor(columns / blockSizeC);
fprintf('\nSize of whole block is %d %d\n\n',wholeBlockRows,wholeBlockCols);
blockNumber=1;
for row = 1 : blockSizeR : rows
for col = 1 : blockSizeC : columns
row1 = row;
row2 = row1 + blockSizeR - 1;
row2 = min(rows, row2);
% Determine starting and ending columns.
col1 = col;
col2 = col1 + blockSizeC - 1;
col2 = min(columns, col2); % Don't let it go outside the image.
% Extract out the block into a single subimage.
oneBlock = grayImage(row1:row2, col1:col2);
glcm=graycomatrix(oneBlock,'NumLevels',16);
disp(glcm);
subplot(16,16,blockNumber);
imshow(oneBlock);
caption2 = sprintf('Block #%d\n of %d', blockNumber,256);
title(caption2, 'FontSize', fontSize);
%drawnow;
blockNumber = blockNumber + 1;
end
end
i has total of 11 rows and 16 columns i.e 185x256 when i calculate the GLCM
i got the error as
Index exceeds number of subplots.
can u tell me how to solve this error...
which line of code should i add to the above code so that it can work well...
i've to only deal with the size 185x256..i dont want to use the function imresize...
댓글 수: 1
Image Analyst
2013년 4월 10일
You could solve this a lot faster than waiting for us if you learn the concepts here: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
채택된 답변
추가 답변 (1개)
Walter Roberson
2013년 4월 10일
0 개 추천
Your code does not define "rows" or "columns"
댓글 수: 6
pammy
2013년 4월 10일
Walter Roberson
2013년 4월 10일
At the command prompt give the command
dbstop if error
and then run your program. When it stops with the error, please show us which line it is stopping on, and a copy of the error message, and please show the values of row, col, and blockNumber
pammy
2013년 4월 10일
Walter Roberson
2013년 4월 10일
What subplot(11,16,blockNumber) ? Your code only shows subplot(16,16,blockNumber)
If you have altered your code to use wholeBlockRows then remember that only counts whole rows, and does not take into account that there might be a partial row (as there is in this situation.)
pammy
2013년 4월 11일
Walter Roberson
2013년 4월 11일
subplotrows = ceil(rows / blockSizeR);
subplotcols = ceil(columns / blockSizeC);
then use
subplot(subplotrows, subplotcols);
카테고리
도움말 센터 및 File Exchange에서 Signal Attributes and Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!