# How to produce self-adjoint filters using Gaussian and motion blur in Matlab?

I am trying to write a Matlab code to produce motion and Gaussian blur. Here is my code:

f0=imread('cameraman.png');
[Nx,Ny,Nz]=size(f0);
if Nz>1;f0=double(rgb2gray(f0));
else
f0=double(f0);
end

blurfilter1 = fspecial('gaussian', [7 7], 1);
blurfilter2 = fspecial('motion',5,30);

Au = @(u) imfilter(u,blurfilter1,'symmetric');

Bu = @(u) imfilter(u,blurfilter2,'symmetric');


In above code, operators Au and Bu will produce Gaussian blur and motion blur respectively. However, I need these two operators to be self-adjoint. I have found the following code for producing self-adjoint opearots but I am not sure whether it works for both Gaussian and blur operators. Here is the code:

Au = @(u) imfilter(imfilter(u,blurfilter1,'symmetric'),blurfilter1','symmetric');
Bu = @(u) imfilter(imfilter(u,blurfilter2,'symmetric'),blurfilter2','symmetric');


# Gaussian

To start, fspecial('gaussian' is deprecated; the fspecial documentation explains how to do the same thing, but better.

Why do you use an n-dimensional convolution (imfilter) if you're actually after 2 sequences of 1-dimensional convolutions?

Something like (excuse me, this is untested, I uninstalled my Matlab recently)

x = [-3:3]
sigma = 1
gaussian = exp(- x.^ 2 / (2 * sigma ^ 2));
self_adjoint_filter = @(img, impresp1d) conv2(impresp1d, impresp1d, img)


should do the trick.

# Motion blur

That's not a self-adjunct operation. It has a definite direction, so eigenvalues can't be the same magnitude.

• Thank you so much for your time and valuable answer. Yes, now I understand that motion blur is not a self-adjoint operator and I am working on the structure of its adjoint. Many thanks.
– eli
Feb 15 at 6:50
• @Marcus, Hi Marcus, maybe i'm wrong, but what if the motion blur kernel were symmetric around the origin ? Feb 15 at 8:32
• then it wouldn't be a motion blur. Feb 15 at 9:01
• as an example, what is wrong with a line centered around origin to be a motion blur kernel? Feb 15 at 9:50
• if you consider it in time domain. the adjoint operator is like the anti-causal version of causal filter. Feb 15 at 16:07

First there are functions convmtx and convmtx2 which returns the matrix operator form of any convolution kernel.

Second, if you consider the convolution operator, the complex sinusoidal are their eigenfunctions and the amplitude of transfer function is their eigenvalues. So, if the operator is selfadjoint, it must have real eigenvalues and in order to have a selfadjoint convolution operator the Fourier transform of kernel must have real values. If a function is real valued in Fourier space then it must have even symmetry in spatial domain.