-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.java
More file actions
56 lines (51 loc) · 1.61 KB
/
Copy pathtest.java
File metadata and controls
56 lines (51 loc) · 1.61 KB
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
/*
* Author: Tsogt Baigalmaa
* Date: Oct 27, 2021
*/
package fingerprintDraft;
public class Neighbors {
public static void main(String[] args) {
boolean[][] testimage1 = { {true, false, true, false, true},
{false, true, false, true, false},
{true, false, true, false, true},
{false, true, false, true, false},
{true, true, true, false, true} };
boolean[][] testimage2 = {{true},{true},{false}};
boolean[] test = getNeighbors(testimage2, 1, 0);
for (boolean b : test) {
System.out.print(b + " ");
}
}
public static boolean[] getNeighbors(boolean[][] image, int row, int col) {
if (row < 0 || col < 0 || row > image.length - 1 || col > image[0].length - 1) {
return null;
}
image = addFrame(image);
boolean[] voisins = new boolean[8];
int[][] clockwise = {{-1, 0},{-1, 1},{0, 1},{1, 1},{1, 0},{1, -1},{0, -1},{-1, -1}};
for (int i = 0; i < 8; ++i) {
voisins[i] = image[row + 1 + clockwise[i][0]][col + 1 + clockwise[i][1]];
}
return voisins;
}
public static boolean[][] addFrame(boolean[][] image) {
boolean[][] frame = new boolean[image.length + 2][image[0].length + 2];
for (boolean entry : frame[0])
entry = false;
for (boolean entry : frame[frame.length - 1])
entry = false;
for (int i = 1; i < frame.length - 1; ++i) {
frame[i][0] = false;
frame[i][frame[0].length - 1] = false;
}
for (int i = 1; i < frame.length - 1; ++i) {
for (int j = 1; j < frame[0].length - 1; ++j) {
frame[i][j] = image[i - 1][j - 1];
}
}
return frame;
// }
//// public static int blackNeighbors(boolean [] neighbors) {
//
}
}