Attempted to access pad_org(1,343); index out of bounds because size(pad_org)=[544,342].

조회 수: 1 (최근 30일)
original_im=imread('Picture1.tif');
figure,imshow(original_im);
pad_org=padarray(original_im,[1 1],'both');
figure(3);imshow(pad_org)
for i=1:size(pad_org,1)-2
for j=1:size(pad_org,2)-2
window=zeros(25,1); %%Matrix to store the value of 5 by 5 window
win_inc=1;%%initial value of window matrix
for k=1:size(window,1)/5
for l=1:size(window,1)/5
window(win_inc)=pad_org(i+k-1,j+l-1);
win_inc=win_inc+1;
end
end
median=sort(window); %%arranging the window by ascending order
new_image(i,j)=median(13);%%13 is the median value of 5 by 5 window
end
end
new_image=uint8(new_image);
figure(4);imshow(new_image);title('Image After Median Filtering')
I am getting an error as
Attempted to access pad_org(1,343); index out of bounds because size(pad_org)=[544,342].
Error in medianfilter_withoutbuiltin (line 54) window(win_inc)=pad_org(i+k-1,j+l-1);
I am unable sort out this error.
Please help me.
Thanks

채택된 답변

Geoff Hayes
Geoff Hayes 2014년 11월 21일
Vetri - your window vector is of size 25x1, and your innermost for loop iterates, with the index l, from one to 5 (25/5). This index is used in the initialization of window at
window(win_inc)=pad_org(i+k-1,j+l-1);
where it is added to j which is the index that starts at one and ends at the number of columns of pad_org less two (so 340). So if j is 340, then when l is four we get
j+l-1 = 340+4-1 = 343
which falls outside the bounds on the number of columns of pad_org. You will need to rethink the window size, or iterate as
for j=1:size(pad_org,2)-4
instead.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by