62 lines
1.9 KiB
C++
62 lines
1.9 KiB
C++
#include "stretchpanel.h"
|
|
#include <QVBoxLayout>
|
|
#include <QDebug>
|
|
#include <QPushButton>
|
|
#include "imageringlist.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)
|
|
{
|
|
QHBoxLayout *layout = new QHBoxLayout(this);
|
|
setLayout(layout);
|
|
|
|
m_stfSlider = new STFSlider(this);
|
|
layout->addWidget(m_stfSlider);
|
|
connect(m_stfSlider, SIGNAL(paramChanged(float, float, float)), this, SIGNAL(paramChanged(float,float,float)));
|
|
|
|
QPushButton *resetButton = new QPushButton(tr("Reset STF"), this);
|
|
resetButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
|
layout->addWidget(resetButton);
|
|
connect(resetButton, SIGNAL(pressed()), this, SLOT(resetMTF()));
|
|
|
|
QPushButton *autoStretchButton = new QPushButton(tr("Autostretch"), this);
|
|
autoStretchButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
|
layout->addWidget(autoStretchButton);
|
|
connect(autoStretchButton, SIGNAL(pressed()), this, SIGNAL(autoStretch()));
|
|
}
|
|
|
|
void StretchPanel::stretchImage(Image *img)
|
|
{
|
|
if(img)
|
|
{
|
|
if(img->rawImage())
|
|
{
|
|
double median, mad;
|
|
img->rawImage()->imageStats(nullptr, nullptr, &median, nullptr, nullptr, &mad);
|
|
median /= img->rawImage()->norm();
|
|
mad /= img->rawImage()->norm();
|
|
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::resetMTF()
|
|
{
|
|
m_stfSlider->setMTFParams(0, 0.5, 1);
|
|
emit paramChanged(0, 0.5, 1);
|
|
}
|
|
|