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

2 Ansichten (letzte 30 Tage)
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)

Antworten (1)

Walter Roberson
Walter Roberson am 12 Mai 2017
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 Kommentare
Walter Roberson
Walter Roberson am 12 Mai 2017
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 am 12 Mai 2017
"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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by