Median (Median) Filter Matlab
조회 수: 7 (최근 30일)
이전 댓글 표시
How to write a function of size 3x3 in Matlab without using Matlab's own ready function for the median (median) filter
댓글 수: 0
답변 (1개)
KALYAN ACHARJYA
2020년 6월 14일
편집: KALYAN ACHARJYA
2020년 6월 14일
disp('##Input Data')
a=randi([1,10],[4,5]) %Any random data
%% # Using MATLAB Function medfilt2
disp('##Using MATLAB Median inbuilt function');
result_MATLAB=medfilt2(a)
%% # Own Custom Function
disp('##Own Median function');
[r c]=size(a);
a_paded=zeros(size(a)+2);
a_paded(2:end-1,2:end-1)=a;
for i=2:r+1
for j=2:c+1
data=a_paded(i-1:i+1,j-1:j+1);
data=sort(data(:));
result_own(i-1,j-1)=data(round(length(data)/2));
end
end
result_own
%You can avoid loop in later section,please see alternate way
Result:
##Input Data
a =
5 3 5 4 8
10 5 3 8 5
4 1 1 2 5
8 1 8 1 3
##Using MATLAB Median inbuilt function
result_MATLAB =
0 3 3 4 0
3 4 3 5 4
1 4 2 3 2
0 1 1 1 0
##Own Median function
result_own =
0 3 3 4 0
3 4 3 5 4
1 4 2 3 2
0 1 1 1 0
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!