-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExcludeColour.c
More file actions
82 lines (74 loc) · 1.68 KB
/
ExcludeColour.c
File metadata and controls
82 lines (74 loc) · 1.68 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
//Skeletonization through the Zhang-Suen algorithm. This function assumes the image is in 0 or 255 binary.
#include <opencv2/opencv.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cassert>
#include "ExcludeColour.h"
#include "DisplayFrames.h"
using namespace std;
using namespace cv;
void excludeColour(Mat image, Mat maskImage, int colour, int display, int position) {
uchar* imagePtr;
uchar* maskPtr;
// maskImage = Mat::zeros(image.rows, image.cols, CV_8UC1);
for( int l = 0; l < image.rows; ++l) {
imagePtr = image.ptr<uchar>(l);
maskPtr = maskImage.ptr<uchar>(l);
for (int m = 0; m < 3*image.cols; m += 3) {
switch (colour) {
case 0:
if (imagePtr[m] > imagePtr[m+1] && imagePtr[m] > imagePtr[m+2]) {
imagePtr[m] = 0;
imagePtr[m+1] = 0;
imagePtr[m+2] = 0;
}
else {
maskPtr[(m+1)/3] = WHITE;
}
break;
case 1:
if (imagePtr[m+1] > imagePtr[m] && imagePtr[m+1] > imagePtr[m+2]) {
imagePtr[m] = 0;
imagePtr[m+1] = 0;
imagePtr[m+2] = 0;
}
else {
maskPtr[(m+1)/3] = WHITE;
}
break;
case 2:
if (imagePtr[m+2] > imagePtr[m+1] && imagePtr[m+2] > imagePtr[m]) {
imagePtr[m] = 0;
imagePtr[m+1] = 0;
imagePtr[m+2] = 0;
}
else {
maskPtr[(m+1)/3] = WHITE;
}
break;
}
}
}
switch (colour) {
case 0:
if(display) {
disImage((char *)"Blue Excluded", image, position);
waitKey(20);
}
break;
case 1:
if(display) {
disImage((char *)"Green Excluded", image, position);
waitKey(20);
}
break;
case 2:
if(display) {
disImage((char *)"Red Excluded", image, position);
waitKey(20);
}
break;
}
}