-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
ApplyGaussianBlur.m
54 lines (47 loc) · 2.43 KB
/
ApplyGaussianBlur.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function [ mBlurredImage ] = ApplyGaussianBlur( mInputImage, gaussianKernelStd, stdToRadiusFactor )
% ----------------------------------------------------------------------------------------------- %
% [ mBlurredImage ] = ApplyGaussianBlur( mInputImage, gaussianKernelStd, stdToRadiusFactor )
% Applies Gaussian Blur on an image
% Input:
% - mInputImage - Input Image.
% Structure: Image Matrix (Single Channel)
% Type: 'Single' / 'Double'.
% Range: [0, 1].
% - gaussianKernelStd - Gaussian Kernel Standard Deviation.
% The STD of Gaussian Kernel used to blur the image.
% Structure: Scalar
% Type: 'Single' / 'Double'.
% Range: (0, inf).
% - stdToRadiusFactor - Standrd Deviation to Radius Factor.
% Used to calclate the radius of the truncated
% Gaussian Kernel.
% Structure: Scalar
% Type: 'Single' / 'Double'.
% Range: (0, inf).
% Output:
% - mOutputImage - Output Image.
% Structure: Image Matrix (Single Channel)
% Type: 'Single' / 'Double'.
% Range: [0, 1].
% Remarks:
% 1. This function is imitation of Photoshop's Gaussian Blur function.
% 2. Each of the channels is processed independently.
% 3. References:
% - http://imagejdocu.tudor.lu/doku.php?id=gui:process:filters
% 4. Prefixes:
% - 'm' - Matrix.
% - 'v' - Vector.
% TODO:
% 1.
% Release Notes:
% - 1.0.001 18/03/2015 Royi Avital
% * Supporting only single channel images.
% - 1.0.000 15/04/2014 Royi Avital
% * First release version.
% ----------------------------------------------------------------------------------------------- %
gaussianBlurRadius = ceil(stdToRadiusFactor * gaussianKernelStd); % Imitating Photoshop - See Reference
vGaussianKernel = exp(-([-gaussianBlurRadius:gaussianBlurRadius] .^ 2) / (2 * gaussianKernelStd * gaussianKernelStd));
vGaussianKernel = vGaussianKernel / sum(vGaussianKernel);
mInputImagePadded = padarray(mInputImage, [gaussianBlurRadius, gaussianBlurRadius], 'replicate', 'both');
mBlurredImage = conv2(vGaussianKernel, vGaussianKernel.', mInputImagePadded, 'valid');
end