how to resolve this error "Index exceeds matrix dimensions."

1 次查看(过去 30 天)
I am implementing HOG and while computing the cell histograms the code give me this error. Here is the code.
% =================================
% Compute Cell Histograms
% =================================
% Computes the histogram for every cell in the image. We'll combine the cells
H = [];
% Create a three dimensional matrix to hold the histogram for each cell.
histograms = zeros(hogParameters.numVertCells, hogParameters.numHorizCells, hogParameters.numBins);
% For each cell in the y-direction...
for row = 0:(hogParameters.numVertCells - 1)
% Compute the row number in the 'img' matrix corresponding to the top
% of the cells in this row. Add 1 since the matrices are indexed from 1.
rowOffset = (row * hogParameters.cellSize) + 1;
% For each cell in the x-direction...
for col = 0:(hogParameters.numHorizCells - 1)
% Select the pixels for this cell.
% Compute column number in the 'img' matrix corresponding to the left
% of the current cell. Add 1 since the matrices are indexed from 1.
colOffset = (col * hogParameters.cellSize) + 1;
% Compute the indices of the pixels within this cell.
rowIndeces = rowOffset : (rowOffset + hogParameters.cellSize - 1);
colIndeces = colOffset : (colOffset + hogParameters.cellSize - 1);
% Select the angles and magnitudes for the pixels in this cell.
cellAngles = angles(rowIndeces, colIndeces); --> error line
cellMagnitudes = magnitude(rowIndeces, colIndeces); --> error line
% Compute the histogram for this cell.
% Convert the cells to column vectors before passing them in.
histograms(row + 1, col + 1, :) = getHistogram(cellMagnitudes(:), cellAngles(:), hogParameters.numBins);
end
At the cellAngles and cellMagnitude it shows error. Kinldy someone resolve this error.
I shall be very thankful for the kind act of consideration.
  4 个评论
Walter Roberson
Walter Roberson 2019-3-24
When I test with a random image, I am not encountering any problem. I have attached my test code.
The problem might depend upon the image you are using. You should dbstop if error and find out which image is causing you problems, and attach that image.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by