# 2D Digital Signal Processing - Applying High Pass on and Image

I have been doing my research on 2D digital signal processing. What I am doing is about noise removal of digital image:

Type of noise that I want to remove from an images is like the Gaussian noise and 'salt and pepper'. For your information, I intend to use the butterworth lowpass filter to remove the noise. This is my code that I used in matlab.

Function Highpass

function [ out ] = butterhp( im,d,n )
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here
h=size(im,1);
w=size(im,2);
[x,y]=meshgrid(-floor(w/2):floor(w-1)/2); -floor(h/2):floor(h-1)/2;
out= 1./(1.+(d./(x.^2+y.^2).^0.5).^(2*n));
end


Function Lowpass

function [ out] = butterlp( im,d,n)
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here
out=1-butterhp(im,d,n);
end


matlab code

a = imread('penang.jpg')
f = rgb2gray(a);
k = imnoise(f,'gaussian')
lp=butterlp(k,15,1);
af=fftshift(fft2(k));
aflp=af.*lp;
aflpi=ifft2(aflp)
noise = uint8(real(aflpi));
imshow(noise)


This is the image that i used. And running the code, this is what I get. So,my problem is when I try to filter it to make it looks more clear by adjusting the number of 'n-th order' and 'cutoff frequency', it seems it does not work. It still gives me blur picture just like that.

• Can't you use Median filter? Its best for salt and pepper noise – Failed Scientist May 17 '16 at 0:23
• Actually, very interesting result :-). – Royi May 17 '16 at 5:37
• actually,my research is about using butterworth low pass filter to remove noise. So, i am trying to make some code of butterworth low pass filter to remove this type of noise. – user18199 May 18 '16 at 17:05
• Why would you use such filter for Denoising of images? – David Jun 25 at 20:37

First things first: If you use fftshift, you have to undo it before doing the ifft. Try

af=fftshift(fft2(k));
aflp=af.*lp;
aflpi=ifft2(ifftshift(aflp))


The result should improve, especially this checkerboard-overlay should go away.

• i try using your suggestion but there is nothing come out. I put the code, then i use "imshow (aflpi)", only white output come out. Can you point out what is wrong with my code? – user18199 May 18 '16 at 17:07
• Check your image. Is it really one value everywhere? Is imshow the problem, i.e. you tried imshow(..., []) or any boundary values instead of []? Have you tried to use abs() instead of real()? – M529 May 18 '16 at 18:24
• Yes, use of fftshift in the middle there would explain the oscillating noise. – Peter K. May 18 '16 at 19:08
• @PeterK. fftshift translates everything by N/2, which is a steep linear phase in the conjugated space. And since he is taking the real part, half of the signal is in the imaginary part. So I am quite certain that this is - at least one of - the problem(s). – M529 May 18 '16 at 21:02
• @M529 : We are in violent agreement, then! – Peter K. May 18 '16 at 21:08