5 x 5 median filter with out inbuilt function

41 views (last 30 days)
I am required to use just median() not medfilt2()
Please help with the code
%% 2. Median Filter
sad1=imread('sadimg.bmp'); %a) Read ‘sadimg.bmp’ store image into ‘sad1’
median_filt=; %b) Make a function ‘median_filt’
re_sad1=; %c) Using ‘medain_filt’, Apply 5x5 median filter to ‘sad1’store result ‘re_sad1’

Answers (1)

Image Analyst
Image Analyst on 4 Oct 2021
I think it wants you do use a double for loop:
[rows, columns] = size(sad1);
re_sad = .....
for col = 1 : columns
for row = 1 : rows
subImage = ..........
re_sad(row, col) = med(.............
end
end
  1 Comment
Image Analyst
Image Analyst on 4 Oct 2021
You need to get a 5x5 subimage at each location and then take the median of that. Here's a hint:
data = randi(99, 6, 6) % Create sample data
subMatrix = data(2:5, 3:4) % Extract a submatrix
data =
69 76 71 12 75 55
32 79 75 50 26 14
95 19 28 96 51 15
4 49 68 34 70 26
44 45 65 58 89 84
38 64 17 23 95 26
subMatrix =
75 50
28 96
68 34
65 58

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by