[TASK] Begin segmenting canny edge into steps.
This commit is contained in:
parent
94e32cd4b9
commit
deb273cc4a
|
@ -290,6 +290,22 @@ class CannyEdgeMachine {
|
||||||
this->showEdges();
|
this->showEdges();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void doFirstStep(void) {
|
||||||
|
this->reset();
|
||||||
|
this->doGaussBlur(); // uses filter_size, filter_sigma
|
||||||
|
this->doGradiants();
|
||||||
|
this->doGradiantMagnitude();
|
||||||
|
};
|
||||||
|
|
||||||
|
void doSecondStep(void) {
|
||||||
|
this->filterLocalMaxima(); // uses t_low only
|
||||||
|
};
|
||||||
|
|
||||||
|
void doThirdStep(void) {
|
||||||
|
this->workLocalMaxima(); // uses t_low & t_high
|
||||||
|
this->showEdges();
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -48,6 +48,7 @@ ImageViewer::ImageViewer() {
|
||||||
original = NULL;
|
original = NULL;
|
||||||
working_copy = NULL;
|
working_copy = NULL;
|
||||||
histogramm_reference = NULL;
|
histogramm_reference = NULL;
|
||||||
|
canny_edge_machine = NULL;
|
||||||
startLogging();
|
startLogging();
|
||||||
generateMainGui();
|
generateMainGui();
|
||||||
renewLogging();
|
renewLogging();
|
||||||
|
@ -649,16 +650,69 @@ void ImageViewer::applyBasicFilterWithOverflowHandling() {
|
||||||
* @brief ImageViewer::runCannyEdge
|
* @brief ImageViewer::runCannyEdge
|
||||||
*/
|
*/
|
||||||
void ImageViewer::runCannyEdge(void) {
|
void ImageViewer::runCannyEdge(void) {
|
||||||
CannyEdgeMachine cem = CannyEdgeMachine(original, working_copy);
|
|
||||||
int filter_size = gauss_filter_size->value();
|
int filter_size = gauss_filter_size->value();
|
||||||
double filter_sigma = gauss_filter_sigma->value();
|
double filter_sigma = gauss_filter_sigma->value();
|
||||||
double t_low = t_low_spinbox->value();
|
double t_low = t_low_spinbox->value();
|
||||||
double t_high = t_high_spinbox->value();
|
double t_high = t_high_spinbox->value();
|
||||||
logFile << "Canny-Edge using N*N filter size: " << filter_size << ", filter sigma: " << filter_sigma << ", and thresholds: " << t_low << ", " << t_high << std::endl;
|
logFile << "Canny-Edge using N*N filter size: " << filter_size << ", filter sigma: " << filter_sigma << ", and thresholds: " << t_low << ", " << t_high << std::endl;
|
||||||
renewLogging();
|
renewLogging();
|
||||||
cem.setGaussFilterParams(filter_size, filter_sigma);
|
canny_edge_machine->setGaussFilterParams(filter_size, filter_sigma);
|
||||||
cem.setThresholdValues(t_low, t_high);
|
canny_edge_machine->setThresholdValues(t_low, t_high);
|
||||||
cem.work();
|
canny_edge_machine->work();
|
||||||
|
updateImageDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the first step of canny edge.
|
||||||
|
*
|
||||||
|
* @brief ImageViewer::runCannyEdgeFirstStep
|
||||||
|
*/
|
||||||
|
void ImageViewer::runCannyEdgeFirstStep(void) {
|
||||||
|
int filter_size = gauss_filter_size->value();
|
||||||
|
double filter_sigma = gauss_filter_sigma->value();
|
||||||
|
double t_low = t_low_spinbox->value();
|
||||||
|
double t_high = t_high_spinbox->value();
|
||||||
|
logFile << "[Step 1] Canny-Edge using N*N filter size: " << filter_size << ", filter sigma: " << filter_sigma << ", and thresholds: " << t_low << ", " << t_high << std::endl;
|
||||||
|
renewLogging();
|
||||||
|
canny_edge_machine->setGaussFilterParams(filter_size, filter_sigma);
|
||||||
|
canny_edge_machine->setThresholdValues(t_low, t_high);
|
||||||
|
canny_edge_machine->doFirstStep();
|
||||||
|
updateImageDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the second step of canny edge.
|
||||||
|
*
|
||||||
|
* @brief ImageViewer::runCannyEdgeSecondStep
|
||||||
|
*/
|
||||||
|
void ImageViewer::runCannyEdgeSecondStep(void) {
|
||||||
|
int filter_size = gauss_filter_size->value();
|
||||||
|
double filter_sigma = gauss_filter_sigma->value();
|
||||||
|
double t_low = t_low_spinbox->value();
|
||||||
|
double t_high = t_high_spinbox->value();
|
||||||
|
logFile << "[Step 2] Canny-Edge using N*N filter size: " << filter_size << ", filter sigma: " << filter_sigma << ", and thresholds: " << t_low << ", " << t_high << std::endl;
|
||||||
|
renewLogging();
|
||||||
|
canny_edge_machine->setGaussFilterParams(filter_size, filter_sigma);
|
||||||
|
canny_edge_machine->setThresholdValues(t_low, t_high);
|
||||||
|
canny_edge_machine->doSecondStep();
|
||||||
|
updateImageDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the third step of canny edge.
|
||||||
|
*
|
||||||
|
* @brief ImageViewer::runCannyEdgeThirdStep
|
||||||
|
*/
|
||||||
|
void ImageViewer::runCannyEdgeThirdStep(void) {
|
||||||
|
int filter_size = gauss_filter_size->value();
|
||||||
|
double filter_sigma = gauss_filter_sigma->value();
|
||||||
|
double t_low = t_low_spinbox->value();
|
||||||
|
double t_high = t_high_spinbox->value();
|
||||||
|
logFile << "[Step 3] Canny-Edge using N*N filter size: " << filter_size << ", filter sigma: " << filter_sigma << ", and thresholds: " << t_low << ", " << t_high << std::endl;
|
||||||
|
renewLogging();
|
||||||
|
canny_edge_machine->setGaussFilterParams(filter_size, filter_sigma);
|
||||||
|
canny_edge_machine->setThresholdValues(t_low, t_high);
|
||||||
|
canny_edge_machine->doThirdStep();
|
||||||
updateImageDisplay();
|
updateImageDisplay();
|
||||||
}
|
}
|
||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
|
@ -922,9 +976,18 @@ void ImageViewer::generateControlPanels() {
|
||||||
task_tab5_scrolllayout->setSizeConstraint(QLayout::SetMaximumSize);
|
task_tab5_scrolllayout->setSizeConstraint(QLayout::SetMaximumSize);
|
||||||
task_tab5_scrollwidget->setLayout(task_tab5_scrolllayout);
|
task_tab5_scrollwidget->setLayout(task_tab5_scrolllayout);
|
||||||
|
|
||||||
run_canny_edge = new QPushButton("Run canny edge algorithm!");
|
run_canny_edge = new QPushButton("Run whole canny edge algorithm!");
|
||||||
QObject::connect(run_canny_edge, SIGNAL(clicked()), this, SLOT(runCannyEdge()));
|
QObject::connect(run_canny_edge, SIGNAL(clicked()), this, SLOT(runCannyEdge()));
|
||||||
|
|
||||||
|
run_canny_edge_first_step = new QPushButton("Do gaussian blur and do gradiants");
|
||||||
|
QObject::connect(run_canny_edge_first_step, SIGNAL(clicked()), this, SLOT(runCannyEdgeFirstStep()));
|
||||||
|
|
||||||
|
run_canny_edge_second_step = new QPushButton("Filter local maxima");
|
||||||
|
QObject::connect(run_canny_edge_second_step, SIGNAL(clicked()), this, SLOT(runCannyEdgeSecondStep()));
|
||||||
|
|
||||||
|
run_canny_edge_third_step = new QPushButton("Work local maxima, show result");
|
||||||
|
QObject::connect(run_canny_edge_third_step, SIGNAL(clicked()), this, SLOT(runCannyEdgeThirdStep()));
|
||||||
|
|
||||||
gauss_filter_size = new QDoubleSpinBox();
|
gauss_filter_size = new QDoubleSpinBox();
|
||||||
gauss_filter_size->setDecimals(0);
|
gauss_filter_size->setDecimals(0);
|
||||||
gauss_filter_size->setMinimum(3);
|
gauss_filter_size->setMinimum(3);
|
||||||
|
@ -946,10 +1009,13 @@ void ImageViewer::generateControlPanels() {
|
||||||
task_tab5_scrolllayout->addWidget(gauss_filter_size);
|
task_tab5_scrolllayout->addWidget(gauss_filter_size);
|
||||||
task_tab5_scrolllayout->addWidget(new QLabel("Gauss filter sigma"));
|
task_tab5_scrolllayout->addWidget(new QLabel("Gauss filter sigma"));
|
||||||
task_tab5_scrolllayout->addWidget(gauss_filter_sigma);
|
task_tab5_scrolllayout->addWidget(gauss_filter_sigma);
|
||||||
|
task_tab5_scrolllayout->addWidget(run_canny_edge_first_step);
|
||||||
task_tab5_scrolllayout->addWidget(new QLabel("Low threshold value"));
|
task_tab5_scrolllayout->addWidget(new QLabel("Low threshold value"));
|
||||||
task_tab5_scrolllayout->addWidget(t_low_spinbox);
|
task_tab5_scrolllayout->addWidget(t_low_spinbox);
|
||||||
|
task_tab5_scrolllayout->addWidget(run_canny_edge_second_step);
|
||||||
task_tab5_scrolllayout->addWidget(new QLabel("High threshold value"));
|
task_tab5_scrolllayout->addWidget(new QLabel("High threshold value"));
|
||||||
task_tab5_scrolllayout->addWidget(t_high_spinbox);
|
task_tab5_scrolllayout->addWidget(t_high_spinbox);
|
||||||
|
task_tab5_scrolllayout->addWidget(run_canny_edge_third_step);
|
||||||
task_tab5_scrolllayout->addWidget(run_canny_edge);
|
task_tab5_scrolllayout->addWidget(run_canny_edge);
|
||||||
|
|
||||||
tabWidget->addTab(task_tab5_widget, "Task #5");
|
tabWidget->addTab(task_tab5_widget, "Task #5");
|
||||||
|
@ -1057,6 +1123,10 @@ void ImageViewer::open() {
|
||||||
delete original;
|
delete original;
|
||||||
original = NULL;
|
original = NULL;
|
||||||
}
|
}
|
||||||
|
if(canny_edge_machine != NULL) {
|
||||||
|
delete canny_edge_machine;
|
||||||
|
canny_edge_machine = NULL;
|
||||||
|
}
|
||||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath());
|
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath());
|
||||||
if(!fileName.isEmpty()) {
|
if(!fileName.isEmpty()) {
|
||||||
working_copy = new LazyImage(new QImage(fileName));
|
working_copy = new LazyImage(new QImage(fileName));
|
||||||
|
@ -1065,6 +1135,7 @@ void ImageViewer::open() {
|
||||||
QMessageBox::information(this, tr("Image Viewer"), tr("Cannot load %1.").arg(fileName));
|
QMessageBox::information(this, tr("Image Viewer"), tr("Cannot load %1.").arg(fileName));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
canny_edge_machine = new CannyEdgeMachine(original, working_copy);
|
||||||
scaleFactor = 1.0;
|
scaleFactor = 1.0;
|
||||||
updateImageDisplay();
|
updateImageDisplay();
|
||||||
printAct->setEnabled(true);
|
printAct->setEnabled(true);
|
||||||
|
|
|
@ -152,11 +152,15 @@ class ImageViewer : public QMainWindow {
|
||||||
QDoubleSpinBox* t_low_spinbox;
|
QDoubleSpinBox* t_low_spinbox;
|
||||||
QDoubleSpinBox* t_high_spinbox;
|
QDoubleSpinBox* t_high_spinbox;
|
||||||
QPushButton* run_canny_edge;
|
QPushButton* run_canny_edge;
|
||||||
|
QPushButton* run_canny_edge_first_step;
|
||||||
|
QPushButton* run_canny_edge_second_step;
|
||||||
|
QPushButton* run_canny_edge_third_step;
|
||||||
|
|
||||||
// "My" space for storing data/results
|
// "My" space for storing data/results
|
||||||
LazyImage* original;
|
LazyImage* original;
|
||||||
LazyImage* working_copy;
|
LazyImage* working_copy;
|
||||||
LazyImage* histogramm_reference;
|
LazyImage* histogramm_reference;
|
||||||
|
CannyEdgeMachine* canny_edge_machine;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
// Custom slots
|
// Custom slots
|
||||||
|
@ -177,6 +181,9 @@ class ImageViewer : public QMainWindow {
|
||||||
void applyBasicFilter();
|
void applyBasicFilter();
|
||||||
void applyBasicFilterWithOverflowHandling();
|
void applyBasicFilterWithOverflowHandling();
|
||||||
void runCannyEdge(void);
|
void runCannyEdge(void);
|
||||||
|
void runCannyEdgeFirstStep(void);
|
||||||
|
void runCannyEdgeSecondStep(void);
|
||||||
|
void runCannyEdgeThirdStep(void);
|
||||||
|
|
||||||
void open();
|
void open();
|
||||||
void openReference();
|
void openReference();
|
||||||
|
|
Loading…
Reference in New Issue