-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathFastAnisotropicCurvaturePreservingSmoothing.m
70 lines (55 loc) · 2.98 KB
/
FastAnisotropicCurvaturePreservingSmoothing.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function [ mOutputImage ] = FastAnisotropicCurvaturePreservingSmoothing( mInputImage, ...
smoothingAmplitude, sharpnessLevel, anisotropyLevel, gradientSmoothness, tensorSmoothness, stepSize )
% ----------------------------------------------------------------------------------------------- %
% [ mOutputImage ] = FastAnisotropicCurvaturePreservingSmoothing( mInputImage, ...
% smoothingAmplitude, spatialPrecision, gradientSmoothness, tensorSmoothness )
% Applies the Fast Anisotropic Curvature Preserving Smoothing on an Input Image
% Input:
% - mInputImage - Input image.
% Matrix, 1 Channels, Floating Point, [0, 1]
% - smoothingAmplitude - Local Window Radius.
% Scalar, Floating Point, {1, 2, ..., 10}.
% - sharpnessLevel - Local Window Gaussian Kernel STD.
% Scalar, Floating Point [0.1, 20].
% - anisotropyLevel - Search Window Radius.
% Scalar, Floating Point, {1, 2, ..., 10}.
% - gradientSmoothness - Weights STD Factor.
% Scalar, Floating Point [0.1, 20].
% - tensorSmoothness - Weights STD Factor.
% Scalar, Floating Point [0.1, 20].
% - stepSize - Weights STD Factor.
% Scalar, Floating Point [0.1, 20].
% Output:
% - mOutputImage - Input image.
% Matrix, 1 Channels, Floating Point, [0, 1]
% Remarks:
% 1. Prefixes:
% - 't' - Tensor.
% - 'm' - Matrix.
% - 'v' - Vector.
% 2. Cl
% TODO:
% 1. aa
% Release Notes:
% - 1.0.000 27/10/2014 Or Yair
% * First release version.
% ----------------------------------------------------------------------------------------------- %
ANGLE_TO_RAD_FACTOR = pi / 180;
gaussianKernelPrecision = 2;
vAngles = [0, 30, 60, 90, 120, 150] * ANGLE_TO_RAD_FACTOR;
numAngles = length(vAngles);
tTensors = CalcImageStructureTensors(mInputImage, sharpnessLevel, anisotropyLevel, gradientSmoothness, tensorSmoothness);
mOutputImage = zeros( size(mInputImage) );
for fieldAngle = vAngles
tTensorField(:, :, 1) = (tTensors(:, :, 1) * cos(fieldAngle)) + (tTensors(:, :, 2) * sin(fieldAngle));
tTensorField(:, :, 2) = (tTensors(:, :, 2) * cos(fieldAngle)) + (tTensors(:, :, 3) * sin(fieldAngle));
tTensorField(:, :, 3) = sqrt((tTensorField(:, :, 1) .* tTensorField(:, :, 1)) + (tTensorField(:, :, 2) .* tTensorField(:, :, 2)));
dln = stepSize ./ tTensorField(:, :, 3);
tTensorField(:, :, 1) = tTensorField(:, :, 1) .* dln;
tTensorField(:, :, 2) = tTensorField(:, :, 2) .* dln;
mFsigma = tTensorField(:, :, 3) * (sqrt(2 * smoothingAmplitude));
mLength = gaussianKernelPrecision * mFsigma;
mOutputImage = mOutputImage + ApplyImageLineIntegralConvolution(mInputImage, tTensorField, mLength, stepSize);
end
mOutputImage = mOutputImage / numAngles;
end