Skip to content

Commit b36d602

Browse files
committed
cleanup code and add comments
1 parent e4ab26a commit b36d602

File tree

9 files changed

+22
-150
lines changed

9 files changed

+22
-150
lines changed

include/CLD.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,27 @@
22
#include <opencv2/opencv.hpp>
33
#include "ETF.h"
44

5-
65
using namespace std;
76

87
#define M_PI 3.14159265358979323846
98
#define SIGMA_RATIO 1.6
10-
#define BINARIZATION_THRESHOLDING 200
11-
#define BIAS 200
129
#define STEPSIZE 1.0
1310

14-
class CLD
15-
{
11+
class CLD {
1612
public:
1713
CLD();
1814
CLD(cv::Size);
1915
void init(cv::Size);
2016
void readSrc(string);
2117
void genCLD();
22-
18+
void combineImage();
2319
// Perform eq.(6) on each pixel
2420
void gradientDoG(cv::Mat& src, cv::Mat& dst, const double rho, const double sigma_c);
25-
2621
// Perform eq.(9) on each pixel
2722
void flowDoG(cv::Mat& src, cv::Mat& dst, const double sigma_m);
28-
2923
// eq.(10)
3024
void binaryThresholding(cv::Mat& src, cv::Mat& dst, const double tau);
3125

32-
// re-initialize the filter input by superimposing the black edge pixels of the previous binary output upon the original image I
33-
void combineImage();
34-
3526
cv::Mat originalImg;
3627
cv::Mat DoG;
3728
cv::Mat FDoG;
@@ -42,5 +33,4 @@ class CLD
4233
double sigma_m;
4334
double rho;
4435
double tau;
45-
4636
};

include/ETF.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,13 @@ class ETF {
88
ETF();
99
ETF(cv::Size);
1010
void Init(cv::Size);
11-
//void operator=(const ETF &in);
12-
//void ReadSrc(string);
13-
void ReadFlow(string, cv::Size);
14-
void gen_ETF(string, cv::Size);
11+
void initial_ETF(string, cv::Size);
1512
void refine_ETF(int kernel);
16-
//void GVF();
1713
void rotateFlow(cv::Mat& src, cv::Mat& dst, float theta);
1814

19-
cv::Mat GVF; // gradient vector flow
2015
cv::Mat gradientMag; // Normalized gradient magnitude
2116
cv::Mat flowField; // edge tangent flow
2217
cv::Mat refinedETF; // ETF after refinement
23-
cv::Mat RotationMat;
24-
25-
int halfw;
26-
int smoothPasses;
2718

2819
private:
2920
void resizeMat(cv::Size);
@@ -32,5 +23,4 @@ class ETF {
3223
float computeWs(cv::Point2f x, cv::Point2f y, int r);
3324
float computeWm(float gradmag_x, float gradmag_y);
3425
float computeWd(cv::Vec3f x, cv::Vec3f y);
35-
3626
};

include/gui.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
#include <wx/filedlg.h>
88
#include <wx/wfstream.h>
99

10-
class MyApp: public wxApp
11-
{
10+
class MyApp : public wxApp {
1211
public:
1312
virtual bool OnInit();
1413
};
1514

16-
class BasicDrawPane : public wxPanel
17-
{
15+
class BasicDrawPane : public wxPanel {
1816

1917
public:
2018
BasicDrawPane(wxPanel* parent, cv::Size, bool canUndo);
@@ -26,14 +24,13 @@ class BasicDrawPane : public wxPanel
2624
string processingS;
2725
void paintEvent(wxPaintEvent& evt);
2826
void paintNow(bool);
29-
void render( wxDC& dc,bool );
27+
void render(wxDC& dc, bool);
3028
DECLARE_EVENT_TABLE()
3129
private:
3230
bool activateDraw;
3331
};
3432

35-
class MyFrame: public wxFrame
36-
{
33+
class MyFrame : public wxFrame {
3734
public:
3835
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
3936
BasicDrawPane *drawPane;
@@ -87,8 +84,7 @@ class MyFrame: public wxFrame
8784
wxDECLARE_EVENT_TABLE();
8885
};
8986

90-
enum
91-
{
87+
enum {
9288
// Menu > File
9389
ID_ONOPENSRC = 1,
9490
ID_ONSAVE,

include/postProcessing.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
using namespace std;
55

6-
class PP
7-
{
6+
class PP {
87
public:
98
PP(cv::Size);
109
void ETF(cv::Mat &flowfield, cv::Mat &dis);

src/CLD.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void CLD::readSrc(string file) {
5656
DoG = Mat::zeros(Size(originalImg.cols, originalImg.rows), CV_32FC1);
5757
FDoG = Mat::zeros(Size(originalImg.cols, originalImg.rows), CV_32FC1);
5858

59-
etf.gen_ETF(file, originalImg.size());
59+
etf.initial_ETF(file, originalImg.size());
6060
//genCLD();
6161
}
6262

@@ -193,6 +193,10 @@ void CLD::binaryThresholding(Mat & src, Mat & dst, const double tau) {
193193
}
194194
}
195195

196+
/**
197+
* re-initialize the filter input
198+
* by superimposing the black edge pixels of the previous binary output upon the original image
199+
*/
196200
void CLD::combineImage() {
197201
for (int y = 0; y < originalImg.rows; y++) {
198202
for (int x = 0; x < originalImg.cols; x++) {
@@ -204,5 +208,6 @@ void CLD::combineImage() {
204208
}
205209
}
206210

211+
// Blur a little-bit to let image more smooth
207212
GaussianBlur(originalImg, originalImg, Size(3, 3), 0, 0);
208213
}

src/ETF.cpp

Lines changed: 5 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -16,48 +16,15 @@ ETF::ETF(Size s) {
1616

1717
void ETF::Init(Size s) {
1818
flowField = Mat::zeros(s, CV_32FC3);
19-
GVF = Mat::zeros(s, CV_32FC3);
2019
refinedETF = Mat::zeros(s, CV_32FC3);
2120
gradientMag = Mat::zeros(s, CV_32FC3);
22-
23-
halfw = 4;
24-
smoothPasses = 2;
25-
}
26-
27-
void ETF::ReadFlow(string file, Size s) {
28-
FILE *stream = fopen(file.c_str(), "rb");
29-
if (!stream) {
30-
//std::cout<<"ERROR!! Can't read "<<featurefile<<'\n';
31-
return;
32-
}
33-
34-
int vf_w, vf_h;
35-
int sint = sizeof(int);
36-
37-
fread((void *)&(vf_w), sint, 1, stream);
38-
fread((void *)&(vf_h), sint, 1, stream);
39-
40-
int sfloat = sizeof(float);
41-
float *data = new float[vf_w*vf_h * 2];
42-
fread((void *)(data), sfloat, vf_w*vf_h * 2, stream);
43-
44-
resize(flowField, flowField, Size(vf_w, vf_h), 0, 0, CV_INTER_LINEAR);
45-
46-
47-
for (int j = 0; j < vf_h; j++) {
48-
for (int i = 0; i < vf_w; i++) {
49-
int index = j*vf_w + i;
50-
float dx = data[index * 2 + 1];
51-
float dy = data[index * 2];
52-
flowField.at<Vec3f>(vf_h - j - 1, i) = Vec3f(dx, -dy, 0.0); //x,y swap??
53-
54-
}
55-
}
56-
resize(flowField, flowField, s, 0, 0, CV_INTER_LINEAR);
5721
}
5822

59-
//Generate ETF of input image as flowfield
60-
void ETF::gen_ETF(string file, Size s) {
23+
/**
24+
* Generate initial ETF
25+
* by taking perpendicular vectors(counter-clockwise) from gradient map
26+
*/
27+
void ETF::initial_ETF(string file, Size s) {
6128
resizeMat(s);
6229

6330
Mat src = imread(file, 1);
@@ -70,20 +37,11 @@ void ETF::gen_ETF(string file, Size s) {
7037
Mat grad_x, grad_y, abs_grad_x, abs_grad_y;
7138
Sobel(src_n, grad_x, CV_32FC1, 1, 0, 5);
7239
Sobel(src_n, grad_y, CV_32FC1, 0, 1, 5);
73-
normalize(grad_x, abs_grad_x, 0, 1, NORM_MINMAX);
74-
normalize(grad_y, abs_grad_y, 0,1,NORM_MINMAX);
75-
//convertScaleAbs(grad_y, abs_grad_y);
7640

7741
//Compute gradient
78-
Mat magn;
7942
magnitude(grad_x, grad_y, gradientMag);
8043
normalize(gradientMag, gradientMag, 0.0, 1.0, NORM_MINMAX);
8144

82-
//Show gradient
83-
//imshow("Magnitude", grad_x);
84-
//imshow("Magni5tude", grad_y);
85-
//waitKey();
86-
8745
flowField = Mat::zeros(src.size(), CV_32FC3);
8846
for (int i = 0; i < src.rows; i++) {
8947
for (int j = 0; j < src.cols; j++) {
@@ -125,9 +83,6 @@ void ETF::computeNewVector(int x, int y, const int kernel) {
12583
float w_m = computeWm(gradientMag.at<float>(y, x), gradientMag.at<float>(r, c));
12684
float w_d = computeWd(t_cur_x, t_cur_y);
12785
t_new += phi*t_cur_y*w_s*w_m*w_d;
128-
//printf("%f, %f, %f, %f, (%f, %f)\n", phi, w_s, w_m, w_d, t_cur_y[1], t_cur_y[1]);
129-
130-
//if(t_new == Vec3f(0,0,0))t_new=t_cur_x;
13186
}
13287
}
13388
refinedETF.at<Vec3f>(y, x) = normalize(t_new);
@@ -162,64 +117,6 @@ float ETF::computeWd(cv::Vec3f x, cv::Vec3f y) {
162117
return abs(x.dot(y));
163118
}
164119

165-
//void ETF::GVF()
166-
//{
167-
// //Mat tmp_n = Mat::zeros(Size(256, 256), CV_32FC3);
168-
//
169-
// ////Addition_B is CV_32F ,but we need CV_32FC3 to store vec3f
170-
// ////create 3 same CV_32F channel and merge to create CV_32FC3 Mat
171-
// //vector<Mat> channels;
172-
// //Mat c = Mat::zeros(tmp_n.size(), CV_32F);
173-
// //Addition_B.convertTo(c, CV_32F, 255);
174-
// //channels.push_back(c);
175-
// //channels.push_back(c);
176-
// //channels.push_back(c);
177-
// //merge(channels, tmp_n);
178-
//
179-
// //normalize(tmp_n, tmp_n, 0.0, 1.0, NORM_MINMAX, CV_32FC3);
180-
// //GaussianBlur(tmp_n, tmp_n, Size(91, 91), 0, 0);
181-
//
182-
// ///// Generate grad_x and grad_y
183-
// //Mat dX, dY;
184-
// //Sobel(tmp_n, dX, CV_32F, 1, 0, 3, 1, 0, 1);
185-
// //Sobel(tmp_n, dY, CV_32F, 0, 1, 3, 1, 0, 1);
186-
//
187-
// //gvf = Mat::zeros(tmp_n.size(), CV_32FC3);
188-
// //for (int i = 0; i < tmp_n.rows; i++)
189-
// //{
190-
// // for (int j = 0; j < tmp_n.cols; j++)
191-
// // {
192-
// // Vec3f u = dX.at<cv::Vec3f>(i, j) / 255.0; //-255~255
193-
// // Vec3f v = dY.at<cv::Vec3f>(i, j) / 255.0;
194-
//
195-
// // float x = u.dot(u);
196-
// // float y = v.dot(v);
197-
// // float z = v.dot(u);
198-
// // float temp = y*y - 2.0*x*y + x*x + 4.0*z*z;
199-
// // float lambda1 = 0;
200-
// // lambda1 = 0.5 * (y + x + sqrt(temp));
201-
// // gvf.at<cv::Vec3f>(i, j) = normalize(Vec3f(z,x - lambda1, 0.0));
202-
//
203-
// // if (gvf.at<cv::Vec3f>(i, j) == Vec3f(0.0, 0.0, 0.0))
204-
// // {
205-
// // gvf.at<cv::Vec3f>(i, j) = Vec3f(0.0, 1.0, 0.0);
206-
// // }
207-
// // }
208-
// //}
209-
//
210-
// //for (int i = 0; i < gvf.rows; i++)
211-
// //{
212-
// // for (int j = 0; j < gvf.cols; j++)
213-
// // {
214-
// // Vec3f v = gvf.at<cv::Vec3f>(i, j);
215-
// // gvf.at<cv::Vec3f>(i, j) = Vec3f(-v[1], v[0], 0.0);
216-
// // }
217-
// //}
218-
// //resize(gvf, gvf, Mask.size(), 0, 0, CV_INTER_LINEAR);
219-
// //flowField = gvf.clone();
220-
//
221-
//}
222-
223120
void ETF::rotateFlow(Mat& src, Mat& dst, float theta) {
224121
theta = theta / 180.0 * M_PI;
225122

@@ -236,7 +133,6 @@ void ETF::rotateFlow(Mat& src, Mat& dst, float theta) {
236133

237134
void ETF::resizeMat(Size s) {
238135
resize(flowField, flowField, s, 0, 0, CV_INTER_LINEAR);
239-
resize(GVF, GVF, s, 0, 0, CV_INTER_LINEAR);
240136
resize(refinedETF, refinedETF, s, 0, 0, CV_INTER_LINEAR);
241137
resize(gradientMag, gradientMag, s, 0, 0, CV_INTER_LINEAR);
242138
}

src/gui.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,8 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
164164
leftside->Fit(drawpanel);
165165
SetSizer(sizer);
166166

167-
168-
169167
this->GetSizer()->Layout();
170-
171-
172168
render_loop_on = false;
173-
174169
}
175170
void MyFrame::OnExit(wxCommandEvent& event) {
176171
Close(true);

src/main.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ BEGIN_EVENT_TABLE(BasicDrawPane, wxPanel)
66
END_EVENT_TABLE()
77

88

9-
109
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
1110
// Menu - File
1211
EVT_MENU(ID_ONOPENSRC, MyFrame::OnOpenSrc)

src/postProcessing.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using namespace cv;
55

66
PP::PP(Size s) {}
77

8+
// visualize the ETF
89
void PP::ETF(Mat &flowfield, Mat &dis) {
910
const float M_PI = 3.14159265358979323846;
1011
Mat noise = Mat::zeros(cv::Size(flowfield.cols / 2, flowfield.rows / 2), CV_32F);
@@ -51,6 +52,7 @@ void PP::ETF(Mat &flowfield, Mat &dis) {
5152
}
5253
}
5354

55+
// visualize ETF by drawing red arrowline
5456
void PP::FlowField(cv::Mat & flowfield, cv::Mat & dis) {
5557
const int resolution = 10;
5658

0 commit comments

Comments
 (0)