I have a grayscale image image named tumour.
I need to find the area where the intensity is greater than 0.
I have another variable outline showing the outline of original image.
G1 is an empty array.
To find it properly, I have used this code:
for i=1:200
for j=1:200
if((outline(i,j)>0) && sum(sum(tumor(i-5,j-5),tumor(i+5,j+5)))>0)
G1(i,j)=255;
end
end
end
I want to get the outline of only the tumour.
However, I am getting this error (in the sum() part) and I am unable to solve it:
Error using sum
Dimension argument must be a positive integer scalar, a vector of unique positive integers, or 'all'.

 채택된 답변

Mehmed Saad
Mehmed Saad 2020년 5월 12일
편집: Mehmed Saad 2020년 5월 12일

0 개 추천

I donot understand what you are trying to do in the code. There are much simpler ways to do it.
By looking in your code i think the error is occuring because your for loop index starts from i=1 and ends at i= 200. When you access i-5 or j-5 it will give error because you are indexing negative values to tumor. SImilarly when your loop reaches end it will try to access 200+5 which is out of bound. So run you for loop from
i=1+5:200-5
&
j=1+5:200-5
Edit:
(tumor(i-5,j-5),tumor(i+5,j+5))
and i think what you are intended to do in this line is accessings tumor's i-5th to i+5th index and j-5th to j+5th index( i.e. total 11x11 elements) . AM i right?

댓글 수: 3

Meenal Shah
Meenal Shah 2020년 5월 12일
I basically wish to get the sum of block of 10x10 cells. I wish to then check if the sum of this entire block is greater than 0.
Also, I tried editing the code as you said, but it showed no change in the error.
Thank you for helping me.
Mehmed Saad
Mehmed Saad 2020년 5월 12일
편집: Mehmed Saad 2020년 5월 12일
Try to generate 10x10 array from tumor For example tumor(1:10,1:10)
Now try to index it in two for loops of yours such that index doesnot exceed tumor dimension
Meenal Shah
Meenal Shah 2020년 5월 13일
편집: Meenal Shah 2020년 5월 13일
Thank you so much. It worked when I tried doing that.
Hope you stay safe.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2019b

질문:

2020년 5월 12일

편집:

2020년 5월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by