## Convolution and deconvolution

Several Gwyddion functions do convolutions and deconvolutions of some sort. A subtle point which is occasionaly a source of confusion is the difference between continuous and discrete operations. When images f and g are physical quantities, i.e. fields sampled in space, their convolution h

is again a physical field. Its physical dimension (units) is

For images dim(A) has the dimension of image area, i.e. usually square metres.

When the integral is realized using a discrete Riemann sum

the area appears as the area of one pixel ΔA. This is how all Gwyddion convolution, deconvolution and transfer function operations work by default, i.e. with the Normalize as integral option enabled.

In digital image processing physical units are sometimes ignored and convolution understood as simple discrete convolution of images

It is possible to obtain this behaviour by disabling the option Normalize as integral in a particular function. You should be aware the result of the operation is then no longer a physical quantity sampled in space (it depends on pixel size) and the units are different. The only function which works this way by default is Convolution Filter, where one of the operands is given as a small matrix of unitless numbers.

### Image convolution Data ProcessMultidataConvolve

Convolution of two images can be performed using Convolve (see Convolution Filter for convolution with a small kernel, entered numerically). The module has only a few options:

Convolution kernel
The smaller image to convolve the larger image with, for instance a tip transfer function image. The dimensions of one pixel in both images must correspond.
Exterior type
What values should be assumed for pixels outside the image (as in Extend).
Output size
The size of the resulting image with respect to which pixels entered the calculation. Crop to interior cuts the image to consists only of pixels that are sufficiently far from the boundary that the exterior does not matter. Keep size creates an image with the same as the input image. Finally, Extend to convolved means the resulting image will be extended on each side by half the kernel size.

### Image deconvolution A simple regularized deconvolution of two images can be performed using Deconvolve. L-curve method can be used to search for the optimum regularization parameter, however its applicability highly depends on the data. The module has the following options:

Convolution kernel
The kernel to be deconvolved from the current image.
Sigma
Regularization parameter.
L-curve display
The data to be shown in the optional L-curve plot, when this is computed. The L-curve consist of two data sources: difference between the result convolved with the kernel and the original data and norm of the result. These two are plotted in a log-log graph providing a L-curve, but their dependences on the regularization parameters can be plotted also individually. The curvature of the resulting curve vs. regularization parameter gives the usual criterion for the best regularization parameters, seeking for the curve maximum.
L-curve sigma range
Range of the regularization parameter to be used in the L-curve calculation. This is, similarly to the regularization parameter, logarithmic, so it can span very large range, not necessarily suitable for the particular data set.

Output type Deconvolved produces the deconvolved image; Difference calculates the difference between reconvolved image and the input. Screenshot of the deconvolve dialogue after L-curve data were computed.

### Transfer function estimation

The probe transfer function (or point spread function) can be estimated from measured data, even noisy, when the corresponding ideally sharp signal is available. Gwyddion currently implements a few relatively simple methods.

Data ProcessingStatisticsTransfer Function Guess. The user interface of the module is and a typical performance on simulated noisy data is shown in the following figures.

The sharp signal is selected as Ideal response. It must have the same dimensions as the image. In contrast to the general Deconvolve module this module is optimized for the statistical properties of the transfer functions. There are currently three available deconvolution methods:

Regularised filter

Simple frequency-space filter with constant regularisation term. It produces transfer function image of the same size as the input images. Option TF zoom can be used to display zoomed central part of the image.

Least squares

The transfer function is found by solving the least squares problem corresponding to the deconvolution. The size of transfer function can be chosen arbitrarily. Usually it is much smaller than the input images.

Parameter Size controls the transfer function image size. If Border is nonzero, the transfer function image is enlarged by this value before solving the least squares problem and then the border is cut. A small border of 2 or 3 often improves the result because errors tend to accumulate in the edge pixels. Both sizes can be estimated automatically using .

Wiener filter

Pseudo-Wiener filter assuming the spectral density of the output can be estimated by the spectral density of the input image. It is again a frequency-domain filter, producing transfer function image of the same size as the input images. Option TF zoom can be used to display zoomed central part of the image.

Two important parameters influence the result. The dimensionless regularisation parameter σ, which is used in all the methods, but is not directly comparable between them. It can be chosen manually. Since suitable values can differ by several orders of magnitude, it is presented as base-10 logarithm. However, the module can find a suitable value also automatically when is pressed.

determines the windowing function applied to both input images before deconvolution. Unless the input data are periodic, windowing is a necessity to avoid cross-like artefacts in the transfer function. The default Welch window is usually a good choice.

A few characteristics of the transfer function are immediately displayed in the bottom part of the dialogue as Result:

TF width
Width, calculated as square root of dispersion when the transfer function is taken as a distribution. Only the central peak is included in the calculation (which is important namely for regularised and Wiener filters). Usually, the optimal reconstruction has also small width.
TF height
Maximum value of the transfer function. When it starts to decrease noticeably, the regularisation parameter is probably too high.
TF norm
Mean square value of the transfer function.
Difference norm
Mean square value of the difference between the input image and ideal sharp image convolved with the reconstructed transfer function.

The tab Output Options allows choosing the images the function will produce: the transfer function (Transfer function), its convolution with the ideal sharp image (Convolved) and/or the difference between the input and the convolved image (Difference). For methods which produce full-size transfer function images, Only zoomed part limits the output image size to the zoomed part displayed in the dialogue. Screenshot of the transfer function estimation module. Sample results of the transfer function estimation module.

An alternative method of TF estimation is the fitting of an explicit function form, for instance Gaussian. The free parameters of the function are sought to minimise the sum of squared differences between measured data and ideal response convolved with the TF. Since the minimisation can be performed entirely in the frequency domain and does not require repeated convolution, this method is simple and fast, albeit somewhat crude. It is available as Data ProcessingStatisticsTransfer Function Fit with three model functions currently implemented: fully symmetrical Gaussian, anisotropic Gaussian which can have different widths in the horizontal and vertical directions, and TF which is exponential in the frequency space.
{"ft_lang_label":"__label__en","ft_lang_prob":0.8835292,"math_prob":0.97671777,"size":5379,"snap":"2023-40-2023-50","text_gpt3_token_len":1026,"char_repetition_ratio":0.15888372,"word_repetition_ratio":0.061831154,"special_character_ratio":0.17921546,"punctuation_ratio":0.09012876,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9803512,"pos_list":[0,1,2,3,4,5,6,7,8,9,10],"im_url_duplicate_count":[null,5,null,5,null,5,null,5,null,5,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-05T02:06:11Z\",\"WARC-Record-ID\":\"<urn:uuid:35c87eaf-c63f-4459-b7b4-a72b782d207e>\",\"Content-Length\":\"17271\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:34a89bd0-25b9-4df2-a898-2978009797fb>\",\"WARC-Concurrent-To\":\"<urn:uuid:001ae5d5-4bfa-4941-b77c-3d7363b28b82>\",\"WARC-IP-Address\":\"217.198.114.120\",\"WARC-Target-URI\":\"http://gwyddion.net/documentation/user-guide-en/convolution-deconvolution.html\",\"WARC-Payload-Digest\":\"sha1:ERLCXOFM3OQSJQSXEVQZ5UT7JWZ63RU2\",\"WARC-Block-Digest\":\"sha1:36HKWRUXDJPBF67UXT5U2K4MYL66SD57\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100540.62_warc_CC-MAIN-20231205010358-20231205040358-00491.warc.gz\"}"}