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...
1 回表示 (過去 30 日間)
古いコメントを表示
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/
採用された回答
Ahmed A. Selman
2013 年 4 月 10 日
Just add
clear
at the very top of the code. Also these issues:
Line 26: change (oneBlocl) to (oneBlock)
Line 30: define the variable (blocks)
Line 31: define (fontSize) in the title argument
perhaps you want to add the command
clc
inside the loops to clean the screen while running (makes run a little bit faster)
After I've made the above minor fixes, it worked fine.
10 件のコメント
Ahmed A. Selman
2013 年 4 月 11 日
Sure Pammy, it is your code and I only tried to slightly modify it for you. Please do not hesitate if you needed further modifications. Regards.
Ahmed A. Selman
2013 年 4 月 11 日
But you used a smart technique in the original code, why not extending it if you want to change the block numbers?
Anyway, I've modified it a little bit further as below (works for any blockSizeR and blockSizeC) as:
... % the above lines are the same.
disp(glcm);
if (blockNumber>blockSizeC*blockSizeR);return;end
subplot(blockSizeC,blockSizeR,blockNumber);
imshow(oneBlock);
... % the rest of the code is the same.
notice the new (if) statement. I've tried the new modifications at
blockSizeR=10 and blockSizeC=16;
blockSizeR=20 and blockSizeC=20;
blockSizeR=11 and blockSizeC=11;
and all worked fine.
その他の回答 (1 件)
Walter Roberson
2013 年 4 月 10 日
Your code does not define "rows" or "columns"
6 件のコメント
Walter Roberson
2013 年 4 月 11 日
subplotrows = ceil(rows / blockSizeR);
subplotcols = ceil(columns / blockSizeC);
then use
subplot(subplotrows, subplotcols);
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!