Open In App

How to Apply Median Filter For RGB Image in MATLAB?

Filtering by definition is the process of enhancing or modifying an image by applying some method or algorithm over a small area and extending that algorithm over all the areas of the image. Since we apply the methods over an area, filtering is classified as a neighboring operation. 

Filters are essentially a matrix of values which when hovered over our region of interest in our image give new values by the mathematical computations depending on what type of filter is being applied. One of the popular and widely used filters is the Median Filter.  



Advantages of the Median Filter 

Disadvantages of Median Filter 

In this article, we will be discussing how to apply a Median filter for an RGB Image in MATLAB. 

Approach : 

Example:






% Matlab Code for implementing
% a Median Filter on an RGB Image. 
% Reading the Image 
I = imread('GFG.jpeg');
  
% Creating figure window for input image
figure 
  
% Displaying the input image
imshow(I);
  
% Applying the median filter on the image 
J = medfilt3(I,[3,3,3]);
  
% Creating figure window for output image
figure 
  
% Displaying the output image 
imshow(J);

Output:

Figure 1: Input Image 

Figure 2: Output Image

Code Explanation:

Article Tags :