Filter löschen
Filter löschen

Why am I getting "Index in position 1 exceeds array bounds."?

10 Ansichten (letzte 30 Tage)
frank din
frank din am 9 Jan. 2019
Kommentiert: Walter Roberson am 10 Jan. 2019
I'm trying to create a color contrast within an image in order to better visualize the image. This is my code
[X,map] = imread('Red car.jpg');
shadow = ind2rgb(X,map); <== Based on debugging so far, my problem in the editor is at this level
shadow_lab = rgb2lab(shadow);
max_luminosity = 100;
L = shadow_lab(:,:,1)/max_luminosity;
shadow_histeq = shadow_lab;
shadow_histeq(:,:,1) = histeq(L)*max_luminosity;
shadow_histeq = lab2rgb(shadow_histeq);
imshow(shadow_histeq);
This is the entire error message
Index in position 1 exceeds array bounds.
Error in ind2rgb (line 26)
r = zeros(size(a)); r(:) = cm(a,1);
Error in ImageRestoration3 (line 2)
shadow = ind2rgb(X,map);
The values for X and map are 450x800x3 uint8, and [] respectively.
Here's the image
Red car.jpg
  4 Kommentare
Rik
Rik am 9 Jan. 2019
Since it is unlikely you uncovered a bug in ind2rgb, it is probably the case that the input is not in the form it expects.
Therefore, you must either attach the image file (use the attach button), preferably to the question instead of a comment. Alternatively you can post the results of the imread function, so the sizes and data types of X and map.
Shubham Gupta
Shubham Gupta am 10 Jan. 2019
The reason that it's not working is because the 'map' variable is an empty array and in 'ind2rgb' function map changes to 'cm' and when MATLAB try to execute
r(:) = cm(a,1)
inside 'ind2rgb' it throws the error as 1 exceeds the 0 (size of 'cm' variable )
Not sure about the reason why you are getting 'map' as an empty array ?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Rik
Rik am 10 Jan. 2019
Your image is already rgb, so you can skip that line in the first place. You do need to convert to double to have the same result.
IM =double(IM)/255;
  1 Kommentar
Walter Roberson
Walter Roberson am 10 Jan. 2019
.jpg and .jpeg images never have a map. The original JPEG specification does not permit pseudocolor images.
.jpg and .jpeg images can in theory be grayscale, but they rarely are. I have encountered at most 3 of them "in the wild", used for real purposes (not just experiments to prove it can be done.)
.jp2 and .jpeg2000 images can have a map if I recall correctly.
You should assume that .jpg files will be RGB unless proven otherwise.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by