public:image_convolution_in_fourier_domain
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
public:image_convolution_in_fourier_domain [2015/12/02 17:29] – [Computing the Laplacian of an image via deconvolution] fangfufu | public:image_convolution_in_fourier_domain [2018/03/31 00:38] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== 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, | ||
+ | - 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, | ||
+ | |||
+ | 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 ===== | ||
+ | <code matlab> | ||
+ | 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(' | ||
+ | c = a.*b; | ||
+ | out = real(ifft2(c)); | ||
+ | end | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Computing the Laplacian of an image via deconvolution ===== | ||
+ | <code matlab> | ||
+ | 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(' | ||
+ | b(b == 0) = eps; | ||
+ | c = a./b; | ||
+ | out = real(ifft2(c)); | ||
+ | out = out + abs(min(out(: | ||
+ | end | ||
+ | |||
+ | |||
+ | </ |