public:image_convolution_in_fourier_domain

### Table of Contents

# Image convolution and deconvolution in the frequency domain

Image convolution and deconvolution can be performed quickly in the frequency domain. In the frequency domain, pointwise multiplication is convolution, while pointwise division is deconvolution. The pseudo-code of the procedure is:

- Convert your input image into the frequency domain, via fast Fourier transform.
- Pad your convolution kernel with zeros, until it reaches the same size as your input image.
- Convert your convolution kernel into the frequency domain, via fast Fourier transform.
- Pointwise multiply the frequency domain input image and the frequency domain convolution kernel together.
- Convert the product from pointwise multiplication back into the spatial domain via inverse fast Fourier transform.

If you want to perform deconvolution, rather than perform pointwise multiplication in step 4, you do pointwise division. You have to be aware divide-by-zero problem, when you are performing deconvolution. You might want to replace all the zeros with eps().

Below are some Matlab examples. Note that Matlab takes care of the zero-padding inside the fft2() function call.

## Computing the Laplacian of an image via convolution

function [ out ] = get_laplacian( in ) %GET_LAPLACIAN Obtain the Laplacian of an image % This is an implementation of the algorithm described in page 32-35 of % Lightness and Brightness Computation by Retinex-like Algorithms by Eran % Borenstein if size(in, 3) == 3 for i = 1:3 tmp = in(:,:,i); out(:,:,i) = get_laplacian_real(tmp); end else out = get_laplacian_real(in); end end function [ out ] = get_laplacian_real(in) %% Fourier transform input image a = fft2(in); b = fft2(fspecial('laplacian'), size(in, 1), size(in, 2)); c = a.*b; out = real(ifft2(c)); end

## Computing the Laplacian of an image via deconvolution

function [ out ] = inv_laplacian(in) %INV_LAPLACIAN Convert a Laplacian image back to its original if size(in, 3) == 3 for i = 1:3 tmp = in(:,:,i); out(:,:,i) = inv_laplacian_real(tmp); end else out = inv_laplacian_real(in); end end function [out] = inv_laplacian_real(in) %% Fourier transform input image a = fft2(in); b = fft2(fspecial('laplacian'), size(in, 1), size(in, 2)); b(b == 0) = eps; c = a./b; out = real(ifft2(c)); out = out + abs(min(out(:))); end

public/image_convolution_in_fourier_domain.txt · Last modified: 2018/03/31 00:38 by 127.0.0.1