-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTumorDetection.java
67 lines (65 loc) · 2.2 KB
/
TumorDetection.java
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
import java.util.Scanner;
public class TumorDetection {
public static void makeRow(int x[][], String str, int row) {
for(int i = 0; i < str.length(); i++) {
x[row][i] = 0;
if (str.substring(i,i+1).equals("1")){
x[row][i] = 1;
}
}
}
public static boolean compare(int row, int col, int scan[][], int tumor[][]) {
for(int r = 0; r < tumor.length; r++) {
for(int c = 0; c < tumor.length; c++) {
if (scan[r+row][c+col] != tumor[r][c]) {
return false;
}
}
}
return true;
}
public static int[][] rotateTumor(int tumor[][]) {
int newT[][] = new int[tumor.length][tumor.length];
for(int r = 0; r < tumor.length; r++) {
for (int c = 0; c < tumor.length; c++) {
newT[r][c] = tumor[c][tumor.length-r-1];
}
}
return newT;
}
public static void main(String[] args) {
Scanner pen = new Scanner (System.in);
System.out.println("Enter scan");
String x = pen.nextLine();
int scanSize = x.length();
int scan[][] = new int[scanSize][scanSize];
for(int r = 0; r < scanSize; r++ ) {
makeRow(scan,x,r);
x = pen.nextLine();
}
System.out.println("Enter tumor");
x = pen.nextLine();
int tumorSize = x.length();
int tumor[][] = new int[tumorSize][tumorSize];
for(int r = 0; r < tumorSize; r++ ) {
makeRow(tumor,x,r);
x = pen.nextLine();
}
boolean found = false;
for(int rotation = 0; rotation <= 3; rotation++) {
for(int r = 0; r <= scanSize-tumorSize; r++){
for(int c = 0; c <= scanSize-tumorSize; c++) {
if(compare(r,c,scan,tumor)) {
System.out.println("Possible tumor at (" + r + ", " + c + ", " + rotation*90 + ")");
found = true;
}
}
}
tumor = rotateTumor(tumor);
}
if (!found) {
System.out.println("No tumors detected.");
}
pen.close();
}
}