Taking the median filter of two images
2 views (last 30 days)
Show older comments
Hello all,
I'm doing an image processing problem where I'm solving a regularized l1 minimization problem for x_n where N is a 3x3 neighborhood around a given pixel
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/530624/image.png)
to solve this you get that x_n=median([
]) the concatination of the neighborhood from the original image and your previous iteration x_n-1.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/530629/image.png)
I didn't know how to solve this with any built in matlab codes so I just made my own.
The problem is that it's pretty inefficient and I was wondering if you peeps had any suggestions!
here's my code. (note: I didn't/don't really care about the boundy of the image)
for nnn=1:50
I_noisy_update = I_noisy1;
for m=2:size(I_noisy1,1)-1
for n=2:size(I_noisy1,2)-1
neighborhood1 = I_noisy1(m-1:m+1,n-1:n+1); % getting the neighborhood of my original image
neighborhood1 = neighborhood1(:);
neighborhood_orig = I_noisy(m-1:m+1,n-1:n+1); % getting the neighborhood of my updated image
neighborhood_orig=neighborhood_orig(:);
neighborhood = [neighborhood_orig;neighborhood1]; % concatinating the two
I_noisy_update(m,n) = median(neighborhood); % getting this median
end
end
I_noisy1 = I_noisy_update; % update my solution
end
0 Comments
Answers (1)
Pavan Guntha
on 25 Mar 2021
You can refer to the documentation of medfilt2 function which is a part of Image processing toolbox which performs median filtering of an image in two dimensions.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!