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

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 Commenti

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.

Accedi per commentare.

Risposte (1)

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 Commenti

Dear Walter Roberson, I put rgb_image(rgb_image0 ==0) = []; this is because I just want compare the area without transparency value. Originally is a complete image as below:
I'm only select a few points to compare (without go through transparency value) and hope can get E_distance as 0.
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)
rgb_image2 = imread('13100.png');
[x y z] = size(rgb_image2);
load('colormaps.mat');
rgb_image2(rgb_image0 ==0) = [];
image2=im2double(rgb_image2);
hmmdimage2=rgb2hmmd(image2);
map = hmmdmap32;
hist1 = zeros([1 size(map, 1)]);
hmmdimage2=rgb2ind(hmmdimage2,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(hmmdimage2(i+i2, j+j2) + 1) = 1;
end
end
end
for g = 1:size(map,1)
if (gotten(g) == 1)
hist1(g) = hist1(g) + 1;
end
end
end
end
hist1=hist1/sum(hist1)
z = clock;
E_distance = sqrt(sum((hist1-hist1).^2))*0.5;
E_distance
etime(clock,z)
z = clock;
E_distance = sqrt(sum((hist-hist1).^2))*0.5;
E_distance
etime(clock,z)
Dear Walter Roberson How to turn the rgb_image pixel value 0 = [] and prevent it automatically reshapes the array to become a vector? Thanks
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.
"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.

Accedi per commentare.

Categorie

Scopri di più su Images in Centro assistenza e File Exchange

Richiesto:

il 12 Mag 2017

Commentato:

il 12 Mag 2017

Community Treasure Hunt

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

Start Hunting!

Translated by