Skip to content

Commit ef64006

Browse files
committed
fix #7 #31 fix the result on view when the check box "keep border provide by the watershed" is checked. see #31 for more information.
1 parent 413e622 commit ef64006

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

src/image_canvas.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ void ImageCanvas::saveMask() {
8383
_mask.id.save(_mask_file);
8484
if (!_watershed.id.isNull()) {
8585
QImage watershed = _watershed.id;
86-
if (!_ui->checkbox_border_ws->isChecked()) {
87-
watershed = removeBorder(_watershed.id, _ui->id_labels);
88-
}
86+
// if (!_ui->checkbox_border_ws->isChecked()) {
87+
// watershed = removeBorder(_watershed.id, _ui->id_labels);
88+
// }
8989
watershed.save(_watershed_file);
9090
QFileInfo file(_img_file);
9191
QString color_file = file.dir().absolutePath() + "/" + file.baseName() + "_color_mask.png";

src/main_window.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ void MainWindow::changeLabel(QListWidgetItem* current, QListWidgetItem* previous
165165
}
166166

167167
void MainWindow::runWatershed(ImageCanvas * ic) {
168-
ic->setWatershedMask(watershed(ic->getImage(), ic->getMask().id));
168+
QImage iwatershed = watershed(ic->getImage(), ic->getMask().id);
169+
if (!checkbox_border_ws->isChecked()) {
170+
iwatershed = removeBorder(iwatershed, id_labels);
171+
}
172+
ic->setWatershedMask(iwatershed);
169173
checkbox_watershed_mask->setCheckState(Qt::CheckState::Checked);
170174
ic->update();
171175
}
@@ -202,7 +206,7 @@ void MainWindow::updateConnect(const ImageCanvas * ic) {
202206
connect(undo_action, SIGNAL(triggered()), ic, SLOT(undo()));
203207
connect(redo_action, SIGNAL(triggered()), ic, SLOT(redo()));
204208
connect(save_action, SIGNAL(triggered()), ic, SLOT(saveMask()));
205-
connect(checkbox_border_ws, SIGNAL(clicked()), ic, SLOT(update()));
209+
connect(checkbox_border_ws, SIGNAL(clicked()), this, SLOT(runWatershed()));
206210

207211
}
208212

@@ -217,7 +221,7 @@ void MainWindow::allDisconnnect(const ImageCanvas * ic) {
217221
disconnect(undo_action, SIGNAL(triggered()), ic, SLOT(undo()));
218222
disconnect(redo_action, SIGNAL(triggered()), ic, SLOT(redo()));
219223
disconnect(save_action, SIGNAL(triggered()), ic, SLOT(saveMask()));
220-
disconnect(checkbox_border_ws, SIGNAL(clicked()), ic, SLOT(update()));
224+
disconnect(checkbox_border_ws, SIGNAL(clicked()), this, SLOT(runWatershed()));
221225
}
222226

223227
ImageCanvas * MainWindow::newImageCanvas() {

src/utils.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ void idToColor(const QImage &image_id, const Id2Labels& id_label, QImage *result
3737
*pix = label->color.red(); pix++;
3838
*pix = label->color.green(); pix++;
3939
*pix = label->color.blue();
40-
}
40+
} else {
41+
pix = &line_out[x];
42+
pix[0] = 255;
43+
pix[1] = 255;
44+
pix[2] = 255;
45+
}
4146
}
4247
}
4348
}
@@ -105,7 +110,7 @@ cv::Mat convertMat32StoRGBC3(const cv::Mat& mat) {
105110
QImage watershed(const QImage& qimage, const QImage & qmarkers_mask) {
106111
cv::Mat image = qImage2Mat(qimage);
107112
cv::Mat markers_mask = qImage2Mat(qmarkers_mask);
108-
cv::Mat markers(markers_mask.size(), CV_32S);
113+
cv::Mat markers = cv::Mat::zeros(markers_mask.size(), CV_32S);
109114
for (int y = 0; y < markers_mask.rows; y++) {
110115
int* mark = markers.ptr<int>(y);
111116
cv::Vec3b* mask = markers_mask.ptr<cv::Vec3b>(y);

0 commit comments

Comments
 (0)