フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Attempted to access pixels(0,1); index must be a positive integer or logical

1 回表示 (過去 30 日間)
med-sweng
med-sweng 2014 年 3 月 4 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I'm trying to check the 3x3 neighbourhood for some pixel. For that, I did the following:
neighbour_F(1) = pixels(i-1,j-1);
neighbour_F(2) = pixels(i-1,j);
neighbour_F(3) = pixels(i-1,j+1);
neighbour_F(4) = pixels(i,j-1);
neighbour_F(6) = pixels(i,j+1);
neighbour_F(7) = pixels(i+1,j-1);
neighbour_F(8) = pixels(i+1,j);
neighbour_F(9) = pixels(i+1,j+1);
When I ran the code, I got the following error:
Attempted to access pixels(0,1); index must be a positive integer or logical.
Error in similarity (line 40)
neighbour_F(2) = pixels(i-1,j);
Yes, I know that this is since we will get a negative value for "i".
What can be done to avoid such error? I thought of adding if-statements, but, for instance, if I had to do "if i>1" twice (for two different neighbourhoods), will it just enter one of those if-blocks? As, I want to retrieve the value of all the neighbourhoods above.
Thanks.

回答 (1 件)

Image Analyst
Image Analyst 2014 年 3 月 4 日
There is no zeoreth row of a matrix. The first (top) row is number 1, not 0.

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by