0
$\begingroup$

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');

I really appriciate it if anyone could please help me to build self-adjoint Au and Bu operators for Gaussian and motion blur.

$\endgroup$
2

2 Answers 2

0
$\begingroup$

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)
Au = @(img) self_adjoint_filter(img, gaussian)

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.

$\endgroup$
20
  • $\begingroup$ 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. $\endgroup$
    – eli
    Feb 15, 2023 at 6:50
  • $\begingroup$ @Marcus, Hi Marcus, maybe i'm wrong, but what if the motion blur kernel were symmetric around the origin ? $\endgroup$
    – Mohammad M
    Feb 15, 2023 at 8:32
  • $\begingroup$ then it wouldn't be a motion blur. $\endgroup$ Feb 15, 2023 at 9:01
  • $\begingroup$ as an example, what is wrong with a line centered around origin to be a motion blur kernel? $\endgroup$
    – Mohammad M
    Feb 15, 2023 at 9:50
  • 1
    $\begingroup$ if you consider it in time domain. the adjoint operator is like the anti-causal version of causal filter. $\endgroup$
    – Mohammad M
    Feb 15, 2023 at 16:07
1
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ Thank you very much for your valuable answer and your time. $\endgroup$
    – eli
    Feb 15, 2023 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.