Question
clc; clear all; close all; a=imread('cameraman.tif'); figure(1),imshow(a),title('origanal image'); b=imnoise(a,'salt & pepper',.02) figure(2),imshow(b),title('noisy image'); Smax=9; for i=1:254 for j=1:254 n=b(i:i+2,j:j+2) Zmin=min(n(:)); Zmax=max(n(:)); Zmed=median(n(:)); sx=3; sy=3; A1=Zmed-Zmin; A2=Zmed-Zmax; if (A1>0) && (A2<0) B1 = Zxy-Zmin; B2 = Zxy-Zmax; if (B1>0) && (B2<0) b(i:i+2,j:j+2) = n(i, j); break; else b(i:i+2,j:j+2) = Zmed; break; end else sx=sx+2; sy=sy+2; if (sx > Smax) && (sy > Smax) b(i:i+2,j:j+2) = n(i, j); end end end end figure(3),imshow(b),title('denoised image'); i am trying to implement the following algorithm but where the above pro. is wrong i am unable to find .. please help me....... Adaptive median filter changes size of Sxy (the size of the neighborhood) during operation. ? Notation Zmin = minimum gray level value in Sxy Zmax = maximum gray level value in Sxy Zmed = median of gray levels in Sxy Zxy = gray level at coordinates (x, y) Smax = maximum allowed size of Sxy ? Algorithm Level A: A1 = Zmed - Zmin A2 = Zmed - Zmax if A1 > 0 AND A2 < 0, go to level B else increase the window size if window size < Smax, repeat level A else output Zxy Level B: B1 = Zxy - Zmin B2 = Zxy - Zmax if B1 > 0 AND B2 < 0, output Zxy else output Zmed
Expert Answer
John Williams
PhD Expert
Answered Aug 29, 2026
You need to take the contents of the "if" block and make it a function that takes the center location and the window size as input arguments. Then in the "else" block you need to increase the window size and call the function. Something like
% Determine window size. if (A1>0) && (A2<0) windowSize = standardSize; % 3 or whatever else windowSize = % your formula for bigger window end % Make the assignment. newImage(x,y) = GetMedian(x,y,windowSize)
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related adaptive median fi... Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →