Skip to content

Commit 8cf88ac

Browse files
Fix livewire with salience map
1 parent d17bf8a commit 8cf88ac

File tree

5 files changed

+53
-36
lines changed

5 files changed

+53
-36
lines changed

segmentation/gradient/saliency/saliency.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Saliency::Saliency(QWidget *parent) :
99
{
1010
ui->setupUi(this);
1111
saliencyImage = nullptr;
12+
weightedSaliencyImage = nullptr;
1213
_name = "Salience map";
1314
connect(ui->pbLoad, SIGNAL(clicked()), this, SLOT(loadSaliency()));
1415
connect(ui->lePath, SIGNAL(textChanged(QString)), this, SLOT(updateArcWeightParams()));
@@ -20,6 +21,7 @@ Saliency::Saliency(QWidget *parent) :
2021
Saliency::~Saliency()
2122
{
2223
iftDestroyImage(&saliencyImage);
24+
iftDestroyImage(&weightedSaliencyImage);
2325
delete ui;
2426
}
2527

@@ -45,6 +47,24 @@ const iftImage *Saliency::getSaliencyImage()
4547
return saliencyImage;
4648
}
4749

50+
const iftImage *Saliency::getWeightedSaliencyImage()
51+
{
52+
float factor = ui->sbSaliencyFactor->value();
53+
54+
if (!weightedSaliencyImage) {
55+
const iftImage *saliency = getSaliencyImage();
56+
const iftImage *img = view->getImage();
57+
weightedSaliencyImage = iftCreateImageFromImage(saliency);
58+
59+
60+
for (int p = 0; p < weightedSaliencyImage->n; p++) {
61+
weightedSaliencyImage->val[p] = factor * saliency->val[p] + (1 - factor) * img->val[p];
62+
}
63+
}
64+
65+
return weightedSaliencyImage;
66+
}
67+
4868
void Saliency::generate()
4969
{
5070
float adjRelRadius = ui->sbAdjRel->value();
@@ -105,6 +125,13 @@ void Saliency::loadSaliency()
105125
void Saliency::updateSaliencyPath()
106126
{
107127
iftDestroyImage(&saliencyImage);
128+
iftDestroyImage(&weightedSaliencyImage);
129+
}
130+
131+
void Saliency::updateArcWeightParams()
132+
{
133+
iftDestroyImage(&weightedSaliencyImage);
134+
ArcWeightFunction::updateArcWeightParams();
108135
}
109136

110137
void Saliency::preprocess()

segmentation/gradient/saliency/saliency.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,21 @@ class Saliency : public ArcWeightFunction
1818
~Saliency();
1919

2020
const iftImage *getSaliencyImage();
21+
const iftImage *getWeightedSaliencyImage();
2122
public slots:
2223
void generate() override;
2324

2425

2526
private slots:
2627
void loadSaliency();
2728
void updateSaliencyPath();
29+
void updateArcWeightParams() override;
2830

2931
private:
3032
Ui::Saliency *ui;
3133

3234
iftImage *saliencyImage;
35+
iftImage *weightedSaliencyImage;
3336

3437
void preprocess() override;
3538

segmentation/livewire/livewire.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ LiveWire::LiveWire(MainWindow *parent, View *view) :
3232
connect(ui->rbNoOrientaion, SIGNAL(toggled(bool)), this, SLOT(changeOrientationMethod()));
3333
connect(ui->rbForce, SIGNAL(toggled(bool)), this, SLOT(changeOrientationMethod()));
3434
connect(ui->rbSalience, SIGNAL(toggled(bool)), this, SLOT(changeOrientationMethod()));
35+
connect(ui->rbSalience, SIGNAL(toggled(bool)), this, SLOT(selectSalienceMethod(bool)));
36+
3537

3638
QAction *foo = new QAction(this);
3739
foo->setShortcut(Qt::CTRL | Qt::Key_Z);
@@ -269,11 +271,7 @@ QList<iftImage*> LiveWire::generateLabel()
269271

270272
void LiveWire::notifyGradientUpdate(ArcWeightFunction *function)
271273
{
272-
saliency = dynamic_cast<Saliency*>(function);
273-
ui->rbSalience->setEnabled(saliency != nullptr);
274-
if (!saliency) {
275-
ui->rbNoOrientaion->setChecked(true);
276-
}
274+
this->currentArcWeightFunction = function;
277275
}
278276

279277
void LiveWire::renderGraphics(iftImage *orig, iftImage *image, QGraphicsPixmapItem *imagePixmap, int sliceType)
@@ -359,7 +357,7 @@ void LiveWire::start()
359357
{
360358
if (saliency && ui->rbSalience->isChecked()) {
361359
try {
362-
imageTmp = saliency->getSaliencyImage();
360+
imageTmp = saliency->getWeightedSaliencyImage();
363361
} catch (QString error) {
364362
QMessageBox::warning((QWidget*) parent,
365363
tr("Warning"),
@@ -474,6 +472,20 @@ void LiveWire::changeOrientationMethod()
474472
ui->gbOrientation->setEnabled(orientationDirectionEnabled);
475473
}
476474

475+
void LiveWire::selectSalienceMethod(bool selected)
476+
{
477+
if (selected) {
478+
saliency = dynamic_cast<Saliency*>(currentArcWeightFunction);
479+
//ui->rbSalience->setEnabled(saliency != nullptr);
480+
if (!saliency) {
481+
QMessageBox::warning((QWidget*) parent,
482+
tr("Warning"),
483+
"You need to choose the salience arc-weight function.");
484+
ui->rbNoOrientaion->setChecked(true);
485+
}
486+
}
487+
}
488+
477489
void LiveWire::paintPath(int *path)
478490
{
479491
if (path) {

segmentation/livewire/livewire.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ private slots:
3535
void undo();
3636
void done();
3737
void changeOrientationMethod();
38+
void selectSalienceMethod(bool selected);
3839

3940
private:
4041
Ui::LiveWire *ui;
@@ -59,6 +60,8 @@ private slots:
5960
iftImage *origImage[4];
6061
iftImage *tmpRenderImage[4];
6162

63+
ArcWeightFunction *currentArcWeightFunction = nullptr;
64+
6265
int *path;
6366
QVector<int*> segments;
6467
int kpoints;

segmentation/livewire/livewire.ui

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>427</width>
10-
<height>305</height>
10+
<height>157</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -85,7 +85,7 @@
8585
<item>
8686
<widget class="QRadioButton" name="rbSalience">
8787
<property name="enabled">
88-
<bool>false</bool>
88+
<bool>true</bool>
8989
</property>
9090
<property name="text">
9191
<string>Salience Image</string>
@@ -158,34 +158,6 @@
158158
</layout>
159159
</widget>
160160
</item>
161-
<item>
162-
<widget class="QGroupBox" name="gbSalienceMap">
163-
<property name="title">
164-
<string>Salience Map</string>
165-
</property>
166-
<layout class="QVBoxLayout" name="verticalLayout_3">
167-
<property name="leftMargin">
168-
<number>0</number>
169-
</property>
170-
<property name="topMargin">
171-
<number>0</number>
172-
</property>
173-
<property name="rightMargin">
174-
<number>0</number>
175-
</property>
176-
<property name="bottomMargin">
177-
<number>0</number>
178-
</property>
179-
<item>
180-
<widget class="QCheckBox" name="cbSalience">
181-
<property name="text">
182-
<string>CheckBox</string>
183-
</property>
184-
</widget>
185-
</item>
186-
</layout>
187-
</widget>
188-
</item>
189161
</layout>
190162
</widget>
191163
<resources>

0 commit comments

Comments
 (0)