-
Notifications
You must be signed in to change notification settings - Fork 0
/
Algorithm for brain cancer detection.txt
268 lines (235 loc) · 4.9 KB
/
Algorithm for brain cancer detection.txt
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#include <stdio.h>
#include <time.h>
#include <graphics.h>
#include <stdlib.h>
#include<math.h>
#include<iostream>
using namespace std;
void ellipseMidpoint(float, float, float, float);
void drawEllipse(float, float, float, float);
void calc(int,int);
int Quadrant1(int [],int [],int );//FUNCTIONS USED FOR EACH lobes of brain.
int Quadrant2(int [],int [],int);
int Quadrant3(int [],int[],int);
int Quadrant4(int[],int[],int);
void max(int []);
int main()
{
srand(time(NULL));
float xc, yc, rx, ry;
initwindow(500, 300, "BRAIN TUMORS");
int x4 = 1, y4 = 1;
for (int i = 1;i <= 500; i++) {
line(x4, y4, 500, y4);
y4 += 4;
}
int x5 = 1, y5 = 1;
for (int i = 1;i <= 500; i++) {
line(x5, y5, x5, 300);
x5 += 4;
}
xc=250;
yc=150;
rx=80;
ry=100;
int c1=0;
int c2=0;
int nx[10];
int ny[10];
setcolor(YELLOW);
setfillstyle(SOLID_FILL, BLUE);
line(250,15,250,295);
line(155,150,345,150);
ellipseMidpoint(xc, yc, rx, ry);
int count=0;
setfillstyle(SOLID_FILL,RED);
while(count<10) //number of circles
{
int a = (rand() % 160) + 170;//random values
int b = (rand() % 200) + 50;
int xw=0;
xw=(pow((250-a),2)/(80*80))+(pow((150-b),2)/(100*100));//ellipse formula to check the point inside ellipse
if(xw<1||xw==0)//condition to be spots inside ellipse
{
nx[c1++]=a;
ny[c2++]=b;
count++;
}
}
for(int j=0;j<count;j++)
{
circle(nx[j],ny[j],5);
floodfill (nx[j],ny[j], RED);
}//putting circles
int q1=Quadrant1(nx,ny,count);
cout<<"NUMBER OF CANCER SPOTS IN FRONTAL LOBE:"<<q1<<"\n";
cout<<"\n";
int q2=Quadrant2(nx,ny,count);
cout<<"NUMBER OF CANCER SPOTS IN PARIENTAL LOBE:"<<q2<<"\n";
cout<<"\n";
cout<<"\n";
int q3=Quadrant3(nx,ny,count);
cout<<"NUMBER OF CANCER SPOTS IN OCCIPITAL LOBE:"<<q3<<"\n";
cout<<"\n";
cout<<"\n";
int q4=Quadrant4(nx,ny,count);
cout<<"NUMBER OF CANCER SPOTS IN TEMPORAL LOBE:"<<q4<<"\n";
cout<<"\n";
cout<<"\n";
int aspots[4]={q1,q2,q3,q4};
max(aspots);
getch();
}
void ellipseMidpoint(float xc, float yc, float rx, float ry) {//ellipse Midepoint
float rxSq = rx * rx;
float rySq = ry * ry;
float x = 0, y = ry, p;
float px = 0, py = 2 * rxSq * y;
drawEllipse(xc, yc, x, y);
//Region 1
p = rySq - (rxSq * ry) + (0.25 * rxSq);
while (px < py) {
x++;
px = px + 2 * rySq;
if (p < 0)
p = p + rySq + px;
else {
y--;
py = py - 2 * rxSq;
p = p + rySq + px - py;
}
drawEllipse(xc, yc, x, y);
//delay(30);
}
//Region 2
p = rySq*(x+0.5)*(x+0.5) + rxSq*(y-1)*(y-1) - rxSq*rySq;
while (y > 0)
{
y--;
py = py - 2 * rxSq;
if (p > 0)
p = p + rxSq - py;
else {
x++;
px = px + 2 * rySq;
p = p + rxSq - py + px;
}
drawEllipse(xc, yc, x, y);
// delay(30);
}
}
void drawEllipse(float xc, float yc, float x, float y)
{
putpixel(xc+x, yc+y, YELLOW);
calc(xc+x,yc+y);
putpixel(xc-x, yc+y, YELLOW);
calc(xc-x,yc+y);
putpixel(xc+x, yc-y,YELLOW);
calc(xc+x,yc-y);
putpixel(xc-x, yc-y, YELLOW);
calc(xc-x,yc-y);
}
int Quadrant1(int x[],int y[],int count)
{
int count1=0;//counters for circles in quadrant1.
for(int i=50;i<=150;i++)//for y lines
{
for(int j=250;j<=330;j++)//for x lines
{
for(int k=0;k<count;k++)//for circles i.e circles are 6
{
if((x[k]==j)&&(y[k]==i))
count1++;
}
}
}
return count1;
}
int Quadrant2(int x[],int y[],int count)
{
int count1=0;//counters for circles in quadrant 2
for(int i=50;i<=150;i++)//for y lines
{
for(int j=170;j<=250;j++)//for x lines
{
for(int k=0;k<count;k++)//for circles i.e circles are 6
{
if((x[k]==j)&&(y[k]==i))
count1++;
}
}
}
return count1;
}
int Quadrant3(int x[],int y[],int count)
{
int count1=0;//counters for circles in quadrant1.
for(int i=150;i<=250;i++)//for y lines
{
for(int j=170;j<=250;j++)//for x lines
{
for(int k=0;k<count;k++)//for circles i.e circles are 6
{
if((x[k]==j)&&(y[k]==i))
count1++;
}
}
}
return count1;
}
int Quadrant4(int x[],int y[],int count)
{
int count1=0;//counters for circles in quadrant1.
for(int i=150;i<=250;i++)//for y lines
{
for(int j=250;j<=330;j++)//for x lines
{
for(int k=0;k<count;k++)//for circles i.e circles are 6
{
if((x[k]==j)&&(y[k]==i))
count1++;
}
}
}
return count1;
}
void max(int max1[])//Sorting (Bubble sort)
{
int temp;
int temp1;
//int size=sizeof(max1)/sizeof(int);
//cout<<size;
int t[4]={1,2,3,4};
for(int i=0;i<4;i++)
{
for(int j=0;j<4-i-1;j++)
{
if(max1[j]>max1[j+1])
{
temp1=t[j];
t[j]=t[j+1];
t[j+1]=temp1;
temp = max1[j];
max1[j] =max1[j+1];
max1[j+1] = temp;
}
}
}
cout<<"THE MAXIMUM CANCER SPOTS ARE :"<<max1[3]<<"IN LOBE:"<<t[3];
}
void calc(int x1,int y1)//logic for drawing pixels
{
int rem=x1%4;
int rem1=y1%4;
if(rem!=0)
{
x1-=rem;
}
if(rem1!=0)
{
y1-=rem1;
}
int a[]={x1,y1,x1+4,y1,x1+4,y1+4,x1,y1+4,x1,y1};
setcolor(RED);
fillpoly(5,a);//filling the polygon
}