-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrandsOperator.h
145 lines (126 loc) · 6.12 KB
/
strandsOperator.h
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
//
// strandsOperator.h
/*
*
* Author: Zhongrui Li
* Supervisor: Wonsook Lee
* EECS, Faculty of Engineering, University of Ottawa, Canada
*
* Date: March 20th, 2015
*
*/
#ifndef __test__strandsOperator__
#define __test__strandsOperator__
#include <stdio.h>
#include "cv.h"
#include "highgui.h"
#include "matlabhelper.h"
#include "splineController.h"
using namespace std;
using namespace cv;
class strandsOperator
{
public:
strandsOperator();
matlabHelper mh;
splineController spCtr;
vector<vector<Point2f> > ctrlPts;
vector<vector<Point2f> > curCurves;
Mat input_img;
Mat StrandsAnalysis(const Mat & _imgErosion);
// Function to detect bifurcate points on a binary image (background is white and lines are black).
// Bifurcate points are points that have 3 neighbor points (black) in its 8 neighbors.
/* Arguments:
* _imgErosion - the input binary image
* Returns:
* bifPts - the coordinate of the bifurcate points.
*/
vector<Point2f> DetectBifuPoints(const Mat & _imgErosion);
// Function removes bifurcation points in the binary image
/* Arguments:
* _imgErosion - the input binary image wiht bifurcate points
* bifPts - the coordinate of the bifurcate points.
* Returns:
* _imgWithoutBifPts - the image without the bifurcate points.
*/
void RemoveBifuPoints(const Mat & _imgErosion, vector<Point2f> bifPts, Mat & _imgWithoutBifPts);
// Function removes single points in the binary image
/* Arguments:
* _imgWithoutBifPts - the input binary image wiht single points
* bifPts - the coordinate of the bifurcate points.
* Returns:
* _imgWithoutSinglePts - the image without the single points.
*/
void DetectRemoveSinglePoint(const Mat & _imgWithoutBifPts, Mat & _imgWithoutSinglePts);
// Function detects end points in a binary image with line segments (background is white and lines are black).
// End points are points that have only 1 neigbor points are black in its neighbors.
/* Arguments:
* _img - the input binary image
* Returns:
* endPoints - Coordinates of the end points
*/
vector<Point2f> DetectEndPoints(const Mat & _img);
// Function tracks line segments in a binary hair image. It uses the endPts as the current seed to trace the line one
// pixel by one pixel. Ince each line have two end points, this function automatically remove duplicate lines.
/* Arguments:
* _img - the input binary image with line segments.
* endPts - the end points of all the lines in the image.
* Returns:
* lines - all the lines that have been tracked in the binary image, save in the vectors.
*/
vector< vector<Point2f> > TrackLineSegments(const Mat & _img, vector<Point2f> endPts);
// Line Tracing of a bw image(binary)
// Assuming foreground to be in black and background to be in white, this function traces the entire line and requres
// row and column value of any pixel which lies on the line and returns the (row, col) values of tall the point which lie on the line
/* Arguments:
* _img - the input binary image with line segments.
* endPts - the end points of all the lines in the image.
* Returns:
* lines - the line that have been tracked in the binary image, save in the vector.
*/
void LinesTrace(const Mat & _img, Point2f endPt, vector<Point2f> & _line);
// Function removes short lines in binayry image under the constrain of the lengthThreshold
/* Arguments:
* _lines - the line segments.
* _lineLengthThreshold - if the length of the lnesare sharoter than the threshold, the
* lines will the removed. Otherwise, the lines will be keeped.
*/
void RemoveShortLines(vector< vector<Point2f> > & _lines, int _lineLengthThreshold);
// Function removes the duplicate pixel of a line
/* Arguments:
* _lines - the input line segments.
*/
void DuplicateCheck(vector< vector<Point2f> > & _lines);
// Function draw an color image of the spline curves based on the control points
/* Arguments:
* _ctrlPts - the control points of the spline curves.
*/
Mat DrawCurvesImg(const Mat & _img, vector<vector<Point2f> > & _ctrlPts);
// Function removes the duplicate pixel of a line
/* Arguments:
% ctrlPoints - Control points of all the line segments.
% extensionParameter - The parameter that defines the extention
% level.
% connectionThreshold - The threshold that used to estimated the Euclidean
% distance of the two connected points. If
% the distance between two potential connecting points
% is smaller than the threshold, those two points
% should be connected. Otherwise, those
% two points shold not be connected.
% newCtrlPtsNum - The number of the control points on each
% connected splines.
% timesOfExtendAndConnection - Time of the extension and connnection.
% connectionThresholdIncrease - The increase value of the connection
% threshold.
%
% Returns:
% ctrlPoints - Control points of slines
% splines - Piecewise polynomial of splines
*/
vector<vector<Point2f> > ExtendAndConnectSplines(double ExtensionParameter, int connectionThreshold, int newCtrlPtsNum, int maximumIterlation, int connectionThresholdIncrease);
/*Median Filter*/
Mat MedianFilter(int windowLength);
bool ExportCtrlPts(char * filepath, CvRect crop_rect);
};
#endif /* defined(__test__strandsOperator__) */