Commit 4ed87946 authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Add plot windows for each member of the energy.

	* apps/tosgui/dispatcher.cpp,
	* apps/tosgui/dispatcher.hpp: Add several nodes selection.
	* apps/tosgui/qattribute.hpp,
	* apps/tosgui/toscgui.cpp,
	* apps/tosgui/tosgui.cpp: plot each member of the energy function.
parent ace93e2f
......@@ -38,6 +38,8 @@ namespace mln
QObject::connect(attr, SIGNAL(nodeSelected(const point2d&)),
this, SLOT(onNodeSelected(const point2d&)));
QObject::connect(attr, SIGNAL(nodeSelected(const image2d<bool>&)),
this, SLOT(onNodeSelected(const image2d<bool>&)));
}
......@@ -59,6 +61,28 @@ namespace mln
this->doFiltering(win);
}
void
QDispatcher::onNodeSelected(const image2d<bool>& mask)
{
fill(m_mask_selection, false);
int n = 0;
for (unsigned p: m_S)
if (mask[p] or m_mask_selection[m_parent[p]])
{
m_mask_selection[p] = true;
++n;
}
std::cout << "Filtering: " << n << std::endl;
for (qt::MainWindowBase* win : m_windows)
this->doNodeSection(win);
for (auto& win : m_fwins)
this->doFiltering(win);
}
void
QDispatcher::onPointSelected(const point2d& p)
{
......@@ -117,7 +141,7 @@ namespace mln
if (m_mask_selection[m_parent[x]]) {
view[x] = view[m_parent[x]];
} else if (m_mask_selection[x]) {
view[x] = mean[x];
view[x] = mean[m_parent[x]];
}
win->update();
......
......@@ -23,6 +23,7 @@ namespace mln
protected slots:
void onNodeSelected(const point2d& p);
void onNodeSelected(const image2d<bool>& mask);
void onPointSelected(const point2d& p);
private:
......
......@@ -27,14 +27,18 @@ namespace mln
QAttributeBase(const QwtText& name = QString("Attribute") );
signals:
/// \brief Signal emited when a single node is selected
void nodeSelected(const point2d& pt);
/// \brief Signal emited when several nodes are selected.
/// The mask is a boolean image
void nodeSelected(const image2d<bool>& pts);
public slots:
virtual void plotNode(const point2d& pt) = 0;
protected slots:
virtual void onSliderReleased() = 0;
virtual void onSliderReleased(int x) = 0;
protected:
virtual void showFilteringWindow() = 0;
......@@ -61,7 +65,7 @@ namespace mln
virtual bool eventFilter(QObject* obj, QEvent *ev);
private:
virtual void onSliderReleased();
virtual void onSliderReleased(int x);
virtual void showFilteringWindow();
......@@ -113,6 +117,7 @@ namespace mln
this->m_data.clear();
this->m_data.resize(m_num_nodes);
std::cout << "Leaf value: " << m_attr[x] << std::endl;
unsigned n = m_num_nodes;
while (x != m_parent[x]) {
this->m_data[n-1].setX(n-1);
......@@ -121,6 +126,8 @@ namespace mln
--n;
x = m_parent[x];
}
std::cout << "Root value: " << m_attr[x] << std::endl;
this->m_data[0].setX(0);
this->m_data[0].setY(m_attr[x]);
this->m_curve->setSamples(m_data);
......@@ -135,13 +142,16 @@ namespace mln
m_slider->setWindowTitle("Attribute filtering");
m_slider->setMinimum(m_minmax.first);
m_slider->setMaximum(m_minmax.second);
// m_slider->setMinimum(m_minmax.first);
// m_slider->setMaximum(m_minmax.second);
m_slider->setOrientation(Qt::Horizontal);
m_slider->show();
std::cout << "Show filtering " << m_minmax.first << " / "
<< m_minmax.second << std::endl;
QObject::connect(m_slider, SIGNAL(sliderReleased()),
this, SLOT(onSliderReleased()));
QObject::connect(m_slider, SIGNAL(valueChanged(int)),
this, SLOT(onSliderReleased(int)));
}
template <typename V>
......@@ -155,7 +165,7 @@ namespace mln
unsigned i = std::max<int>(0, this->invTransform(QwtPlot::xBottom, p.x()));
unsigned x = m_current;
for (; i < m_num_nodes; ++i)
for (; i < m_num_nodes-1; ++i)
x = m_parent[x];
point2d q = m_parent.point_at_index(x);
......@@ -168,16 +178,15 @@ namespace mln
return QAttributeBase::eventFilter(obj, event);
}
template <typename V>
void
QAttribute<V>::onSliderReleased()
QAttribute<V>::onSliderReleased(int x)
{
int lambda = m_slider->value();
std::cout << "Filtering with lambda < " << lambda << std::endl;
image2d<bool> mask = eval(m_attr < lambda);
emit nodeSelected(mask);
}
}
......
......@@ -23,28 +23,6 @@
namespace mln
{
template <typename T>
image2d<T>
interpolate_k1(const image2d<T>& ima)
{
image2d<T> out(2*ima.nrows()-1, 2*ima.ncols()-1);
typedef point2d P;
mln_foreach(point2d p, ima.domain())
{
T a = ima.at(p),
b = ima.at(p + P{0,1}),
c = ima.at(p + P{1,0}),
d = ima.at(p + P{1,1});
point2d q = 2 * p;
out.at(q) = ima.at(p);
out.at(q + P{0,1}) = (a + b) / 2;
out.at(q + P{1,0}) = (a + c) / 2;
out.at(q + P{1,1}) = (a + b + c + d) / 4;
}
return out;
}
template <typename V, typename W>
......@@ -150,6 +128,10 @@ int main(int argc, char** argv)
image2d<unsigned> parent;
std::tie(K, parent, S) = morpho::ToS(area, c4);
auto Area = morpho::area_compute(K, parent, S, K1::is_face_2);
unsigned maxarea = S[0];
auto Kui8 = transform(K, [maxarea](const unsigned& v) -> uint8 {
......@@ -157,7 +139,8 @@ int main(int argc, char** argv)
});
auto f = interpolate_k1(addborder(ima));
image2d<float> energy = compute_energy(f, K, parent, S);
image2d< internal::energy_t<rgb8> > imacc;
image2d<float> energy = compute_energy(f, K, parent, S, imacc);
image2d<float> cenergy = close(energy, K, parent, S);
qt::MainWindow<uint8> w1(Kui8);
......@@ -181,6 +164,24 @@ int main(int argc, char** argv)
QAttribute<float> wattr3(cenergy, parent, QString("Mumford shah (clo)"));
wattr3.show();
QAttribute<unsigned> wattr4(Area, parent, QString("Grain"));
wattr4.show();
# define IF_NOT_NULL(v, XEXPR) ((v) == 0) ? 0 : (XEXPR);
auto attr5 = transform(imacc,[](const internal::energy_t<rgb8>& x) -> float {
return IF_NOT_NULL(x.m_e_length, x.alpha * x.m_e_sumcurv / x.m_e_length); });
QAttribute<float> wattr5(attr5, parent, QString("Internal Energy (sum_curv / e_length)"));
wattr5.show();
auto attr6 = transform(imacc,[](const internal::energy_t<rgb8>& x) -> float { return IF_NOT_NULL(x.m_v_n_int, x.external_energy()); });
QAttribute<float> wattr6(attr6, parent, QString("External Energy"));
wattr6.show();
auto attr7 = transform(imacc,[](const internal::energy_t<rgb8>& x) -> float { return IF_NOT_NULL(x.m_e_length, x.beta / x.m_e_length); });
QAttribute<float> wattr7(attr7, parent, QString("Constraint Energy"));
wattr7.show();
QDispatcher disp(parent, S);
disp.addImageWindow(&w1);
......@@ -189,6 +190,10 @@ int main(int argc, char** argv)
disp.addAttribute(&wattr1);
disp.addAttribute(&wattr2);
disp.addAttribute(&wattr3);
disp.addAttribute(&wattr4);
disp.addAttribute(&wattr5);
disp.addAttribute(&wattr6);
disp.addAttribute(&wattr7);
// QObject::connect(&main, SIGNAL(pointSelected(const point2d&)),
//&wattr, SLOT(plotNode(const point2d&)));
......
......@@ -7,17 +7,16 @@
#include <mln/io/imread.hpp>
#include <mln/morpho/tos/tos.hpp>
#include <mln/qt/mainwin.hpp>
#include <apps/tos/Kinterpolate.hpp>
#include <mln/morpho/filtering.hpp>
#include <apps/tos/Kinterpolate.hpp>
#include <apps/tos/mumford_shah.hpp>
#include <apps/tos/addborder.hpp>
#include <apps/tos/objdetection.hpp>
#include <mln/qt/mainwin.hpp>
#include "qattribute.hpp"
#include "dispatcher.hpp"
#include "tosapp.hpp"
#include <apps/tos/mumford_shah.hpp>
#include "qattribute.hpp"
#include "dispatcher.hpp"
int main(int argc, char** argv)
......@@ -33,24 +32,45 @@ int main(int argc, char** argv)
image2d<uint8> ima;
io::imread(argv[1], ima);
auto f = interpolate_median(ima, UInt<9> ());
typedef UInt<9> V;
image2d<uint8> bima = addborder(ima);
image2d<uint8> f = interpolate_k1(bima);
image2d<V> ima_ = transform(bima, [](uint8 x) -> V { return x*2; });
//auto f = interpolate_median(addborder(ima), UInt<9> ());
image2d< UInt<9> > K;
std::vector<unsigned> S;
image2d<unsigned> parent;
std::tie(K, parent, S) = morpho::ToS(f, c4);
std::tie(K, parent, S) = morpho::ToS(ima_, c4);
auto Kui8 = transform(K, [](const UInt<9>& v) -> uint8 {
return v / 2;
});
image2d<float> energy = compute_energy(f, K, parent, S);
image2d<float> cenergy = close(energy, K, parent, S);
image2d< internal::energy_t<uint8> > imacc;
image2d<float> energy = compute_energy(bima, K, parent, S, imacc);
image2d<float> cenergy = clone(energy);
{
int lambda = 5;
auto cK = clone(K);
auto cParent = clone(parent);
cenergy[S[0]] = value_traits<float>::max();
getObjects(cenergy, cK, cParent, S, lambda);
cenergy[S[0]] = 0;
}
//image2d<float> cenergy = close(energy, K, parent, S);
image2d<unsigned> Area = morpho::area_compute(K, parent, S, K1::is_face_2);
qt::MainWindow<uint8> w1(Kui8);
w1.show();
qt::MainWindow<uint8> w2(Kui8);
w2.show();
QAttribute<uint8> wattr1(Kui8, parent, QString("Gray values"));
wattr1.show();
......@@ -60,39 +80,39 @@ int main(int argc, char** argv)
QAttribute<float> wattr3(cenergy, parent, QString("Mumford shah (clo)"));
wattr3.show();
image2d<float> energy = compute_energy(f, K, parent, S);
image2d<float> cenergy = close(energy, K, parent, S);
qt::MainWindow<uint8> w1(Kui8);
w1.show();
QAttribute<uint8> wattr1(Kui8, parent, QString("Gray values"));
wattr1.show();
QAttribute<unsigned> wattr4(Area, parent, QString("Grain"));
wattr4.show();
QAttribute<float> wattr2(energy, parent, QString("Mumford shah"));
wattr2.show();
QAttribute<float> wattr3(cenergy, parent, QString("Mumford shah (clo)"));
wattr3.show();
# define IF_NOT_NULL(v, XEXPR) ((v) == 0) ? 0 : (XEXPR);
auto attr5 = transform(imacc,[](const internal::energy_t<uint8> x) -> float {
return IF_NOT_NULL(x.m_e_length, x.alpha * x.m_e_sumcurv / x.m_e_length); });
QAttribute<float> wattr5(attr5, parent, QString("Internal Energy (sum_curv / e_length)"));
wattr5.show();
QDispatcher disp(parent, S);
disp.addImageWindow(&w1);
disp.addAttribute(&wattr1);
disp.addAttribute(&wattr2);
disp.addAttribute(&wattr3);
auto attr6 = transform(imacc,[](const internal::energy_t<uint8> x) -> float { return IF_NOT_NULL(x.m_v_n_int, x.external_energy()); });
QAttribute<float> wattr6(attr6, parent, QString("External Energy"));
wattr6.show();
// QObject::connect(&main, SIGNAL(pointSelected(const point2d&)),
//&wattr, SLOT(plotNode(const point2d&)));
auto attr7 = transform(imacc,[](const internal::energy_t<uint8> x) -> float { return IF_NOT_NULL(x.m_e_length, x.beta / x.m_e_length); });
QAttribute<float> wattr7(attr7, parent, QString("Constraint Energy"));
wattr7.show();
qt::MainWindow<uint8> main(Kui8);
main.show();
QDispatcher disp(parent, S);
disp.addImageWindow(&w1);
disp.addImageWindowToFilter(&w2,
transform(Kui8, [] (uint8 x) -> rgb8 { return rgb8{x,x,x}; })
);
disp.addAttribute(&wattr1);
disp.addAttribute(&wattr2);
disp.addAttribute(&wattr3);
disp.addAttribute(&wattr4);
disp.addAttribute(&wattr5);
disp.addAttribute(&wattr6);
disp.addAttribute(&wattr7);
//disp.addAttribute(&wattr1);
// QObject::connect(&main, SIGNAL(pointSelected(const point2d&)),
//&wattr, SLOT(plotNode(const point2d&)));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment