MATLAB: I did some mistake in the code.the goal is i wanna set 21×21 processing window over 255×255 image ,then i need to find median value by sorting the pixels for each window,then i wanna find difference between each pair of adjacent pixels of sorted pi

Image Processing Toolboxmedianprocessing window 21x21sort

pls find what i wanna change in this code
for n=1:21
for m=1:21
b=noisy_img([n:n+20],[m:m+20]);
b
c=b(:);
d=sort(c);
k=numel(d);
e=median(d);
e
for i=1:k-1
f=d(i+1)-d(i);
f
end
end
end

Best Answer

Why not just use medfilt2()? And what is this algorithm supposed to produce? Your third for loop does nothing but overwrite f 441 times because f is not indexed. In a 21 by 21 window there are 441 pixels, so you'll have 440 differences between pairs. What is the use of f if you could get it working and have all 440 elements of f. What does f represent?