Trying to understand the implementation of Gaussian blur in matlab

I am trying to blur a scanned text document to such an extent that the text lines are blurred to black. I mean, the text is mixed with each other, and all I see is black lines.

I am new to MATLAB, and although I know the basics, I cannot properly lubricate the image. I read this: Gaussian Blurr and according to this, the blur is controlled / determined by the sigma function. But this is not how it works in the code I wrote.

When I tried to study Gaussian blur in Matlab, I came to find out that it was achieved using this function: fspecial('gaussian',hsize,sigma);

Thus, it is obvious that there are two variables hsize indicates the number of rows or columns in the function, and sigma indicates the standard deviation.

Can someone explain the meaning of hsize here and why does it have a much deeper influence on the result even more than sigma ?

Why, even if I increase sigma to a very high value, the blur does not work, but the image is very distorted, increasing hsize

here is my code:

 img = imread('c:\new.jpg'); h = fspecial('gaussian',hsize,sigma); out = imfilter(img,h); imshow(out); 

and the results are attached:

Why is it driven not only by sigma ? What role does hsize play? Why can't I blur this text and not distort the whole image?

thanks

enter image description hereenter image description hereenter image description here

+4
source share
2 answers

hsize refers to the size of the filter. In particular, the Nx x Ny filter uses an Nx x Ny pixel region in a size centered around each pixel when calculating the filter response. The answer is how the pixels in this area are combined together. In the case of the gaussian filter, the intensity of each pixel around the central one is weighted in accordance with the Gaussian function until a square field is performed over the region. sigma refers to Gaussian standard deviations (see documentation for fspecial ) with units in pixels. As sigma increases (saving the filter size is the same), you end up approaching a simple middle box with uniform weighting over the filter area around the central pixel, so you stop seeing the effect of increasing sigma .

The similarities between the results obtained with a Gaussian blur (with a large sigma value) and the box average are shown in the left and middle image below. The correct image shows the blurring results that you probably want.

enter image description here

The code:

 % gaussian filter: hsize = 5; sigma = 10; h = fspecial('gaussian',hsize,sigma); out = imfilter(img,h); % box filter: h = fspecial('average',hsize); out = imfilter(img,h); % erode: se=strel('ball',4,4); out = imerode(img,se); 
+7
source

Fspecial manual

h = fspecial ('gaussian', hsize, sigma) returns a rotational symmetric Gaussian low-pass filter of size hsize with standard sigma deviation (positive). hsize can be a vector defining the number of rows and columns in h, or it can be a scalar, in which case h is a square matrix. The default value for hsize is [3 3]; The default value for sigma is 0.5. Not recommended. Use imgaussfilt or imgaussfilt3.

where they say that fspecial - gaussian not recommended. When determining the standard deviation (sigma), you still need to decide hsize, which affects the blur. In imgaussfilt you choose the standard deviation and the system considers you the rest. I can get much higher tolerance levels with imgaussfilt and imgaussfilt3 on my systems in Matlab 2016a, for example, the output here in body

 im = im2double( imgGray ); sigma = 5; simulatedPsfImage = imgaussfilt(im, sigma); simulatedPsfImage = im2double( simulatedPsfImage ); [ measuredResolution, standardError, bestFitData ] = ... EstimateResolutionFromPsfImage( simulatedPsfImage, [1.00 1.00] ); 

Note that the fspecial tolerance fspecial are set to [0.70 1.30] by default.

+1
source

Source: https://habr.com/ru/post/1495759/


All Articles