Median (Median) Filter Matlab

7 ビュー (過去 30 日間)
ibrahim pangiz
ibrahim pangiz 2020 年 6 月 14 日
編集済み: KALYAN ACHARJYA 2020 年 6 月 14 日
How to write a function of size 3x3 in Matlab without using Matlab's own ready function for the median (median) filter

回答 (1 件)

KALYAN ACHARJYA
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

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by