1 module rip.processing.filters.sobel;
2 
3 private
4 {
5 	import rip.processing.filters.directions;
6 	import rip.processing.filters.linear;
7 }
8 
9 
10 class SobelOperator : LinearFilter
11 {
12 	this(CartesianDirection direction)
13 	{
14 		apertureWidth = 3;
15 		apertureHeight = 3;
16 		apertureDivider = 1.0f;
17 		apertureOffset = 0.0f;
18 
19 		final switch (direction) with (CartesianDirection)
20 		{
21 			case X:
22 				flattenKernel = flatten(
23 					[
24 						[ 1.0f,  0.0f,  -1.0f ],
25 						[ 2.0f,  0.0f,  -2.0f ],
26 						[ 1.0f,  0.0f,  -1.0f ],
27 					]
28 					);
29 				break;
30 			case Y:
31 				flattenKernel = flatten(
32 					[
33 						[  1.0f,   2.0f,    1.0f ],
34 						[  0.0f,   0.0f,    0.0f ],
35 						[ -1.0f,  -2.0f,  -1.0f ],
36 					]
37 					);
38 				break;
39 			case XY:
40 				flattenKernel = flatten(
41 					[
42 						[  1.0f,   0.0f,  -1.0f ],
43 						[  0.0f,   0.0f,   0.0f ],
44 						[ -1.0f,   0.0f,   1.0f ],
45 					]
46 					);
47 				break;
48 		}
49 	}
50 }
51 
52 
53 class AlternativeSobel : LinearFilter
54 {
55 	this(CartesianDirection direction)
56 	{
57 		apertureWidth = 3;
58 		apertureHeight = 3;
59 		apertureDivider = 1.0f;
60 		apertureOffset = 0.0f;
61 
62 		final switch (direction) with (CartesianDirection)
63 		{
64 			case X:
65 				flattenKernel = flatten(
66 					[
67 						[ -1.0f,  0.0f,  1.0f ],
68 						[ -2.0f,  0.0f,  2.0f ],
69 						[ -1.0f,  0.0f,  1.0f ],
70 					]
71 					);
72 				break;
73 			case Y:
74 				flattenKernel = flatten(
75 					[
76 						[  -1.0f,  -2.0f,  -1.0f ],
77 						[   0.0f,   0.0f,   0.0f ],
78 						[   1.0f,   2.0f,   1.0f ],
79 					]
80 					);
81 				break;
82 			case XY:
83 				flattenKernel = flatten(
84 					[
85 						[  1.0f,   0.0f,  -1.0f ],
86 						[  0.0f,   0.0f,   0.0f ],
87 						[ -1.0f,   0.0f,   1.0f ],
88 					]
89 					);
90 				break;
91 		}
92 	}
93 }