フィルターのクリア

Index in position 1 exceeds array bounds (must not exceed 1)

1 回表示 (過去 30 日間)
Luke Butcher
Luke Butcher 2019 年 2 月 27 日
回答済み: Walter Roberson 2019 年 2 月 27 日
Howdy all, super novice here.
Im trying to write a program to reduce the noise on an image by clustering, that is I want to take the value of a single pixel, and if it and at least 3 of its neighbors in a 3x3 area (with the pixel in question at the center) have a value of 1, keep the value of the center pixel at one. otherwise, set the center pixel to 0. Also, i want it to perform this function for all pixels in a 232 X 251 image. One of the problems I'm running into is that I tried to take into account the corner/ border pixels so as not to exceed the array bounds, but i still get an error.
For image named "blackandwhite"
r = size(blackandwhite,1);
c = size(blackandwhite,2);
for r = 2:1:max(r)-1
for c = 2:1:max(c)-1
if ((T(r,c)+T(r+1,c)+T(r-1,c)+T(r+1,c+1)+T(r,c+1)+T(r-1,c+1)+T(r+1,c-1)+T(r,c-1)+T(r-1,c-1)) < 3), T=0;
end
end
end
Anybody have any advice as to how to proceed? Thanks in advance!
(please use small words, still not versed in the jargon of matlab)

採用された回答

Walter Roberson
Walter Roberson 2019 年 2 月 27 日
The first time your if condition is true, you do T=0 which replaces all of T with the scalar 0. Then your loop continues and tries to index using sizes from the original T array, but T has been replaced with just the single 0. You should be assigning to T(r,c) instead of T.
Note: the way you use c = size(blackandwhite,2) and then for c = 2:1:max( c)-1 is confusing, because you are using c with two different meanings there. Also, size() with a dimension number always returns a scalar, so there is no need to look at max() of it.

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by