What is index out of bound ?

1 次查看(过去 30 天)
Prakash Sharma
Prakash Sharma 2015-4-23
Sir i have two files . When i run these codes I get this error.
duplicate
Attempted to access test(29,258,2); index out of bounds because size(test)=[512,512,1].
Error in duplicate>Segment_Callback (line 337)
cimg(i,j,2) = test(i,j,2);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in duplicate (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)duplicate('Segment_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
What the error means and how can I solve it? It is very urgent.. Can you please help me soon.

回答(1 个)

Image Analyst
Image Analyst 2015-4-23
You're trying to assign the green color channel to another image:
cimg(i,j,2) = test(i,j,2);
but it's not a color image and does not have a second color plane. What you should do if you want to have a color image is this:
[rows, columns, numberOfColorChannels] = size(test);
if numberOfColorChannels == 1
% It's a gray scale image. Create a color image from it.
cimg = cat(3, test, test, test);
else
cimg = test; % Already RGB, just assign all color channels to cimg.
end
  3 个评论
Image Analyst
Image Analyst 2015-4-23
In place of the whole i,j loop. You obviously can't use that code because it throws an error. My code will not. If you have one with test(i,j,3) get rid of that also.
Prakash Sharma
Prakash Sharma 2015-4-23
Thank you very much Sir, it worked. I have an extended code related to this. i will be very thankful to u if you kindly help me this time also. these are the codes
I am getting this error
Index exceeds matrix dimensions.
Error in singha>VALIDATE_Callback (line 506) s2 = std2(cimg(:,:,2));
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in singha (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)singha('VALIDATE_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Platform and License 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by