Rework stretch to use just MTF
This commit is contained in:
+30
-56
@@ -1,42 +1,33 @@
|
||||
#include "stretchpanel.h"
|
||||
#include <QVBoxLayout>
|
||||
#include <QDebug>
|
||||
#include <QPushButton>
|
||||
#include "imageringlist.h"
|
||||
#include "stfslider.h"
|
||||
|
||||
const float BLACK_POINT_SIGMA = -2.8f;
|
||||
const float MAD_TO_SIGMA = 1.4826f;
|
||||
const float TARGET_BACKGROUND = 0.25f;
|
||||
|
||||
float MTF(float x, float m)
|
||||
{
|
||||
if(x < 0)return 0;
|
||||
if(x > 1)return 1;
|
||||
return ((m - 1) * x) / ((2 * m - 1) * x - m);
|
||||
}
|
||||
|
||||
StretchPanel::StretchPanel(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||
setLayout(layout);
|
||||
|
||||
m_lowSlider = new QSlider(Qt::Horizontal, this);
|
||||
m_highSlider = new QSlider(Qt::Horizontal, this);
|
||||
m_paramSlider = new QSlider(Qt::Horizontal, this);
|
||||
m_stfSlider = new STFSlider(this);
|
||||
layout->addWidget(m_stfSlider);
|
||||
connect(m_stfSlider, SIGNAL(paramChanged(float, float, float)), this, SIGNAL(paramChanged(float,float,float)));
|
||||
|
||||
STFSlider *stfslider = new STFSlider(this);
|
||||
|
||||
m_lowSlider->setRange(0, UINT16_MAX);
|
||||
m_lowSlider->setPageStep(512);
|
||||
m_highSlider->setRange(0, UINT16_MAX);
|
||||
m_highSlider->setPageStep(512);
|
||||
m_highSlider->setValue(UINT16_MAX);
|
||||
m_paramSlider->setRange(0, UINT16_MAX);
|
||||
m_paramSlider->setPageStep(512);
|
||||
|
||||
m_stretchSelect = new QComboBox(this);
|
||||
m_stretchSelect->addItems({tr("Linear"), tr("Square root"), tr("Power"), tr("Logarithm"), tr("Asinh")});
|
||||
|
||||
layout->addWidget(m_lowSlider);
|
||||
layout->addWidget(m_highSlider);
|
||||
layout->addWidget(m_paramSlider);
|
||||
layout->addWidget(m_stretchSelect);
|
||||
layout->addWidget(stfslider);
|
||||
|
||||
connect(m_lowSlider, SIGNAL(valueChanged(int)), this, SIGNAL(lowChanged(int)));
|
||||
connect(m_highSlider, SIGNAL(valueChanged(int)), this, SIGNAL(highChanged(int)));
|
||||
connect(m_paramSlider, SIGNAL(valueChanged(int)), this, SLOT(calculateParam()));
|
||||
connect(m_stretchSelect, SIGNAL(activated(int)), this, SIGNAL(stretchChanged(int)));
|
||||
connect(m_stretchSelect, SIGNAL(activated(int)), this, SLOT(calculateParam()));
|
||||
QPushButton *resetButton = new QPushButton(tr("Reset STF"), this);
|
||||
resetButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
||||
layout->addWidget(resetButton);
|
||||
connect(resetButton, SIGNAL(pressed()), this, SLOT(resetMTF()));
|
||||
}
|
||||
|
||||
void StretchPanel::imageLoaded(Image *img)
|
||||
@@ -47,36 +38,19 @@ void StretchPanel::imageLoaded(Image *img)
|
||||
{
|
||||
double mean, stdDev, median;
|
||||
img->rawImage()->imageStats(&mean, &stdDev, &median, nullptr, nullptr);
|
||||
double mad = img->rawImage()->MAD();
|
||||
float l = median - mad;
|
||||
m_lowSlider->setValue(l);
|
||||
float p = std::log(0.25)/std::log(mean/UINT16_MAX);
|
||||
m_paramSlider->setValue(p * UINT16_MAX);
|
||||
qDebug() << "Low" << l << p;
|
||||
median /= 65536;
|
||||
double mad = img->rawImage()->MAD() / 65536;
|
||||
float bp = median + mad * BLACK_POINT_SIGMA * MAD_TO_SIGMA;
|
||||
float mid = MTF(median - bp, TARGET_BACKGROUND);
|
||||
m_stfSlider->setMTFParams(bp, mid, 1.0f);
|
||||
emit paramChanged(m_stfSlider->blackPoint(), m_stfSlider->midPoint(), 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StretchPanel::calculateParam()
|
||||
void StretchPanel::resetMTF()
|
||||
{
|
||||
float val = m_paramSlider->value();
|
||||
float param;
|
||||
switch(m_stretchSelect->currentIndex())
|
||||
{
|
||||
case 2:
|
||||
param = val/UINT16_MAX;
|
||||
param = 1.0f / (param * 5.0f + 1);
|
||||
break;
|
||||
case 3:
|
||||
param = val;
|
||||
break;
|
||||
case 4:
|
||||
param = 1.0f/std::max(0.00001f, 1.0f-(val/UINT16_MAX));
|
||||
//val += 100;
|
||||
//param = val/100.0f;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
emit paramChanged(param);
|
||||
m_stfSlider->setMTFParams(0, 0.5, 1);
|
||||
emit paramChanged(0, 0.5, 1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user