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

10 次查看(过去 30 天)
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 个评论
Rik
Rik 2019-1-9
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 2019-1-10
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 ?

请先登录,再进行评论。

回答(1 个)

Rik
Rik 2019-1-10
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 个评论
Walter Roberson
Walter Roberson 2019-1-10
.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.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by