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
|
%--------------------------------------------------------------------------
% This file is part of the ASTRA Toolbox
%
% Copyright: 2010-2016, iMinds-Vision Lab, University of Antwerp
% 2014-2016, CWI, Amsterdam
% License: Open Source under GPLv3
% Contact: astra@uantwerpen.be
% Website: http://www.astra-toolbox.com/
%--------------------------------------------------------------------------
classdef Kernels
%KERNELS Summary of this class goes here
% Detailed explanation goes here
properties
end
methods(Static)
function K = BinaryPixelKernel(radius, conn)
if nargin < 2
conn = 8;
end
% 2D, 4conn
if conn == 4
K = [0 1 0; 1 1 1; 0 1 0];
for i = 2:radius
K = conv2(K,K);
end
K = double(K >= 1);
% 2D, 8conn
elseif conn == 8
K = ones(2*radius+1, 2*radius+1);
% 3D, 6conn
elseif conn == 6
K = zeros(3,3,3);
K(:,:,1) = [0 0 0; 0 1 0; 0 0 0];
K(:,:,2) = [0 1 0; 1 1 1; 0 1 0];
K(:,:,3) = [0 0 0; 0 1 0; 0 0 0];
for i = 2:radius
K = convn(K,K);
end
K = double(K >= 1);
% 2D, 27conn
elseif conn == 26
K = ones(2*radius+1, 2*radius+1, 2*radius+1);
else
disp('Invalid conn')
end
end
end
end
|