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

1 Ansicht (letzte 30 Tage)
Shah Bano
Shah Bano am 23 Mär. 2019
Kommentiert: Walter Roberson am 24 Mär. 2019
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 Kommentare
Walter Roberson
Walter Roberson am 24 Mär. 2019
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by