-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSegmentation.cpp
More file actions
128 lines (123 loc) · 3.07 KB
/
Segmentation.cpp
File metadata and controls
128 lines (123 loc) · 3.07 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
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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <climits>
#include <queue>
#include <set>
#include "Segmentation.h"
using namespace std;
Segmentation::Segmentation()
{
for(int i = 0; i<3; i++)
{
for(int j = 0; j<3; j++)
{
colours[i][j] = 0;
}
}
for(int i = 3; i<6; i++)
{
for(int j = 0; j<3; j++)
{
colours[i][j] = 255;
}
}
for(int i = 0; i<3; i++)
{
colours[i][i] = 255;
}
for(int i = 0; i<3; i++)
{
colours[3+i][2-i] = 0;
}
}
Segmentation::~Segmentation()
{
}
Segmentation::Segmentation(Image& image) : Image(image)
{
for(int i = 0; i<3; i++)
{
for(int j = 0; j<3; j++)
{
colours[i][j] = 0;
}
}
for(int i = 3; i<6; i++)
{
for(int j = 0; j<3; j++)
{
colours[i][j] = 255;
}
}
for(int i = 0; i<3; i++)
{
colours[i][i] = 255;
}
for(int i = 0; i<3; i++)
{
colours[3+i][2-i] = 0;
}
Histogram& h = *(new Histogram(image));
vector <int> threshold = h.getThreshold();
if(threshold.size() != 0)
{
int check = 0,size = threshold.size();
for(int i = 0; i<_height; i++)
{
for(int j = 0; j<_width; j++)
{
int brightness = (image.getColourAtPos(i,j).getRed() + image.getColourAtPos(i,j).getBlue() + image.getColourAtPos(i,j).getGreen())/3;
for(int k = 0; k<size; k++)
{
if(brightness <= threshold[k])
{
if(k < 6)
{
_my_arr[i][j] = *(new Pixel(i,j,*(new Colour(colours[k][0],colours[k][1],colours[k][2]))));
}
else
{
_my_arr[i][j] = *(new Pixel(i,j,*(new Colour(0,0,0))));
}
break;
}
}
if(brightness > threshold[size-1])
{
if(size < 6)
{
_my_arr[i][j] = *(new Pixel(i,j,*(new Colour(colours[size][0],colours[size][1],colours[size][2]))));
}
else
{
_my_arr[i][j] = *(new Pixel(i,j,*(new Colour(0,0,0))));
}
}
}
}
}
else
{
Reflection& ref = *(new Reflection(image));
for(int i = 0; i<_height; i++)
{
for(int j = 0; j<_width; j++)
{
_my_arr[i][j] = *(new Pixel(i,j,ref.getColourAtPos(i,j)));
}
}
}
CompositeImage& com = *(new CompositeImage(image,*this,0.4));
for(int i = 0; i<_height; i++)
{
for(int j = 0; j<_width; j++)
{
_my_arr[i][j] = *(new Pixel(i,j,com.getColourAtPos(i,j)));
}
}
}