Array indices must be positive integers or logical values Error
이전 댓글 표시
rgb = inp(:,:,[1 1 1]);
red = rgb(:,:,1);
red(tumorOutline)= 255;
green = rgb(:,:,2);
green(tumorOutline)= 0;
blue = rgb(:,:,3);
blue(tumorOutline)= 0;
tumorOutlineInserted(:,:,1) = red;
tumorOutlineInserted(:,:,2) = green;
tumorOutlineInserted(:,:,3) = blue;
axes(handles.axes6);
imshow(tumorOutlineInserted);
Why this code give error that array in
dices must be positive integers or logical values
Error in line 3
댓글 수: 3
Star Strider
2021년 6월 29일
... because ‘TumorOutline’ is not a logical index or a positive integer.
It is not obvious what it is.
Please post the complete error message. I would reveal, which line is falling. Either Star Strider's idea is the problem, or this line, if you have redefined "axes" as a local variable:
axes(handles.axes6);
Shindujah Arudchelvan
2021년 6월 30일
편집: Jan
2021년 6월 30일
채택된 답변
추가 답변 (1개)
Image Analyst
2021년 6월 30일
You can't assign certain locations of tumorOutline to be zero when you haven't defined the array.
tumorOutline (erodedImage)=0; // error line
Assuming erodedImage is a logical image of true and false, you're saying that you want the true parts of erodedImage to be black in tumorOutline. Essentially you want tumorOutline to be black where erodedImage is not black. However is the first element is at, say (30, 50) what is it supposed to do with the prios elements, and where is (30,50) in the image? It has not seen tumorOutline before so it has no idea how many rows or columns it has. To fix that particular error, you can declare it somehow, like
tumorOutline = true(size(erodedImage)); % Declare in advance so it knows the size of tumorOutline.
tumorOutline (erodedImage)=0; % No error now;
However there may be other errors and it still may not do what you want due to errors in your algorithm.
카테고리
도움말 센터 및 File Exchange에서 Image Arithmetic에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!