Effacer les filtres
Effacer les filtres

How to compute median of neighboring pixels while using 3 x 3 sliding window?

3 vues (au cours des 30 derniers jours)
shafaq nisar
shafaq nisar le 8 Juin 2017
Commenté : Guillaume le 11 Juin 2017
I want to replace any noisy pixel with the median of neighboring pixels in MATLAB. Kindly guide what code I can use?
I have an image which contains noisy pixels, I want to replace the noisy pixels value with the median of its 8 neighbors median value.
I will be very thankful to all.

Réponses (1)

Guillaume
Guillaume le 8 Juin 2017
filteredimage = medfilt2(yourimage, [3 3]);
Note that the current pixel is included in the median calculation, so that's 9 pixels not 8 taken into account.
  3 commentaires
Image Analyst
Image Analyst le 10 Juin 2017
It's a color image. Either do it one color channel at a time, or convert the image to grayscale.
Guillaume
Guillaume le 11 Juin 2017
Clearly, as the error message tells you, medfilt2 expects a 2D matrix. Therefore, your matrix must be 3D, that is a colour image. You haven't really told us what you want to do in that case. If you want to apply the median filter to each colour channel independently then you can loop over the channels, or use medfilt3 with a size of 1 in the 3rd dimension:
medfilt3(yourcolourimage, [3 3 1])

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by