The first argument of the fspecial() function is the name of the filter, and the second argument is the size of the filter. The filters available in this function are average, disk, gaussian, laplacian, log, motion, etc. If you want to remove noise or to smooth your image, you can use the fspecial() and imfilter() function to create and apply a specific filter to smooth the given image. Creating and Applying the Averaging Filter Using the fspecial() and imfilter() Function in MATLAB
Check this link for more details about the medfilt2() function. The two images are shown side by side using the imshowpair() function. In the above figure, the left image is the noisy image, and the right image is the smoothed image using the median filter. In the above code, we used an already stored image of coins which you can change according to your requirements. Imshowpair(Noisy_image,Smoothed_image,'montage') Noisy_image = imnoise(Input_image,'salt & pepper',0.03) For example, let’s add salt and pepper noise to a given image using the imnoise() function and then smooth it using the medfilt2() function. If the second argument is not given, the function will use the default value, which is 3-by-3.
The first argument of this function is the image you want to smooth, and the second argument is the m-by-n neighborhood value around the pixel of the input image. If you want to remove noise or to smooth your image, you can use the medfilt2() function to create and apply the median filter to smooth the given image. Create and Apply the Median Filter Using the medfilt2() Function in MATLAB
This tutorial will introduce how to create and apply the median or averaging filter using the medfilt2(), fspecial(), and imfilter() function in MATLAB.