Index in position 1 exceeds array bounds (must not exceed 1)
Show older comments
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)
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!