Taking the median filter of two images

3 views (last 30 days)
tiwwexx
tiwwexx on 24 Feb 2021
Commented: tiwwexx on 25 Mar 2021
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
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.
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

Answers (1)

Pavan Guntha
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.
  1 Comment
tiwwexx
tiwwexx on 25 Mar 2021
Hey Pavan Thanks for the responce,
I did look into the use of medfilt2. However for my specific application listed above it doesn't "work". Since I need to concatinate my current itteration with a previous itteration then take the median of that larger set I can't just use medfilt2. I could this of making a 3-d array with the third dimmension being the original image in position 1 and the ittereated image in position 2. Then I could directly use something like medfilt3 (a 3-d median filter). Is there anything like this (an n dimmensional median filter?).

Sign in to comment.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!