image processing loop to calculate median value in window / kernel
이전 댓글 표시
I want to slide through an image matrix and evaluate the median at each frame. The structuring element needs to be 5x5. This is what i have so far:
img = imread('img.jpg');
length = 5;
half = round(length/2);
Len = size(greyscale_Gaussian);
rows = Len(1);
cols = Len(2);
kernel = zeros(5,5);
rowend = (rows - 1);
colend = (col - 1);
for row = 3 : rows -3;
for column = 3: num_cols -3;
up = row + half;
down = rows - half;
right = column + half;
left = cols - half;
startrow = max(up), 1;
endrow = min(down), rowend;
startcolumn = max(left),1;
endcolumn = min(right),colend;
window = W(startrow:endrow, startcolumn:endcolumn); %??
window = ([up:down,right:left]); %??
B(row, column) = median(window);
end
end
Im not sure how to define the window or how to end this script? i dont want to use any inbuilt functions such as imfilter etc.
채택된 답변
추가 답변 (1개)
Image Analyst
2021년 3월 21일
0 개 추천
Why not use the build-in function medfilt2()?
댓글 수: 3
Yas Rebecca
2021년 3월 21일
Image Analyst
2021년 3월 21일
Then can you please accept DGM's answer to give him reputation points?
And it's almost always better to use built-in methods because they've been extensively tested for robustness and validated for accuracy, rather than your own method, which might not think of all the things that could go wrong or have bugs.
DGM
2021년 3월 21일
I second Image Analyst's note about using existing tools. Not only are they typically more robust, but they're often faster. I should've added that the only reason I wrote that sliding window filter was as a fallback for use only when imdilate() wasn't available.
카테고리
도움말 센터 및 File Exchange에서 Image Preview and Device Configuration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!