Lab 4:Image Restoration
In this lab, I review the principle of several kinds of filters. And use the histograms of different figure to determine which kind of noise has been added on the figure. Then I try to use different methods to reduce the noise to restore the original figure.Introduction:
- Question1:
By obverting the histograms of four input figures, we can determine the noise types of them.
We can know the first figure has pepper noise, the second input figure has salt noise, for first two figure, we can use median filter to reduce the noise. The third input figure has alt-and-pepper noise, we can use adaptive median filter. The fourth input figure has Gaussian noise, we can use Gaussian filter to restore the figure.
- Matlab codes:
function f = RAMF(img) % adaptive median filter [Im,In] = size(img); nmin = 3; nmax = 9; Imf = img; I_ex = [zeros((nmax-1)/2,In+(nmax-1));zeros(Im,(nmax-1)/2),img,zeros(Im,(nmax-1)/2);zeros((nmax-1)/2,In+(nmax-1))]; for x = 1:Im for y = 1:In for n = nmin:2:nmax Sxy = I_ex(x+(nmax-1)/2-(n-1)/2:x+(nmax-1)/2+(n-1)/2,y+(nmax-1)/2-(n-1)/2:y+(nmax-1)/2+(n-1)/2); Smax = max(max(Sxy));% Find the maximum number of pixels in the window Smin = min(min(Sxy));%Find the minimum number of pixels in the window Smed = median(median(Sxy));%Find the middle value of pixels in the window % Determine if the median is a noise point if Smed > Smin && Smed < Smax % if the median is both greater than the mini |