필터 지우기
필터 지우기

How to fit the error? Attempted to access hmmdimage(2,2); index out of bounds because size(hmmdi​mage)=[1,9​9918].

조회 수: 2 (최근 30일)
How to fit the error?
Attempted to access hmmdimage(2,2); index out of bounds because size(hmmdimage)=[1,99918].
rgb_image = imread('13100 IP.png');
[x y z] = size(rgb_image);
load('colormaps.mat');
rgb_image0 = rgb_image;
rgb_image(rgb_image0 ==0) = [];
image=im2double(rgb_image);
hmmdimage=rgb2hmmd(image);
map = hmmdmap32;
hist = zeros([1 size(map, 1)]);
hmmdimage=rgb2ind(hmmdimage,map);
for i = 1:x
for j = 1:y
gotten = zeros([size(map, 1) 1]);
for i2 = 1:8
for j2 = 1:8
if (i + i2 <= x && j + j2 <= y)
gotten(hmmdimage(i+i2, j+j2) + 1) = 1;
end
end
end
for g = 1:size(map,1)
if (gotten(g) == 1)
hist(g) = hist(g) + 1;
end
end
end
end
hist=hist/sum(hist)
  댓글 수: 2
KSSV
KSSV 2017년 5월 12일
편집: KSSV 2017년 5월 12일
colormaps.mat file is missing...what is rgb2hmmd function? Error clearly says hmmdimage is a vector. You are trying to access it like a matrix.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2017년 5월 12일
You have
rgb_image(rgb_image0 ==0) = [];
Deleting individual entries from an array (as opposed to rows or columns) automatically reshapes the array to become a vector.
  댓글 수: 4
Walter Roberson
Walter Roberson 2017년 5월 12일
There is no way to prevent the automatic reshaping into a vector when you delete individual entries.
If you were deleting individual entries that you happened to know corresponded to a row or column, then you would have to recode to examine the list of items to delete to detect which row (or column) it was and code the deletion in terms of row or column deletion. But that tactic is not applicable here as you are deleting scattered items in the middle of arrays.
You should change your code so that when it is examining a pixel, it checks to see whether the pixel is transparent and reacts accordingly.
It is not uncommon for it to be most efficient to just process everything and then discard the results corresponding to the areas outside of the region of interest. However, that does not always work.
Walter Roberson
Walter Roberson 2017년 5월 12일
"If you were me, how would you do?"
If I were you, I would be confused.
However, if you were me, you would start by documenting what the purpose of the code is, and the algorithms that you are using to achieve those purposes.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by