#include "stretchtoolbar.h" #include #include #include #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); } StretchToolbar::StretchToolbar(QWidget *parent) : QToolBar(tr("Stretch toolbar"), parent) { setObjectName("stretchtoolbar"); m_stfSlider = new STFSlider(this); addWidget(m_stfSlider); connect(m_stfSlider, SIGNAL(paramChanged(float, float, float)), this, SIGNAL(paramChanged(float,float,float))); QAction *autoStretchButton = addAction(QIcon(":/nuke.png"), tr("Auto Stretch F12")); autoStretchButton->setShortcut(Qt::Key_F12); connect(autoStretchButton, SIGNAL(triggered()), this, SIGNAL(autoStretch())); QAction *resetButton = addAction(style()->standardIcon(QStyle::SP_DialogResetButton), tr("Reset Screen Transfer Function F11")); resetButton->setShortcut(Qt::Key_F11); connect(resetButton, &QAction::triggered, this, &StretchToolbar::resetMTF); QAction *invertButton = addAction(QIcon(":/invert.png"), tr("Invert colors")); invertButton->setCheckable(true); connect(invertButton, SIGNAL(toggled(bool)), this, SIGNAL(invert(bool))); QAction *superPixelButton = addAction(QIcon(":/bayer.png"), tr("Debayer CFA")); superPixelButton->setCheckable(true); connect(superPixelButton, SIGNAL(toggled(bool)), this, SIGNAL(superPixel(bool))); m_autoStretchOnLoad = addAction(QIcon(":/nuke_a.png"), tr("Apply auto stretch on load")); m_autoStretchOnLoad->setCheckable(true); } void StretchToolbar::stretchImage(Image *img) { if(img) { if(img->rawImage()) { double median, mad, max; img->rawImage()->imageStats(nullptr, nullptr, &median, nullptr, &max, &mad); median /= img->rawImage()->norm(); mad /= img->rawImage()->norm(); max /= img->rawImage()->norm(); if(max>1.0f)max = 1.0f; float bp = median + mad * BLACK_POINT_SIGMA * MAD_TO_SIGMA; float mid = MTF(median - bp, TARGET_BACKGROUND); m_stfSlider->setMTFParams(bp, mid, max); emit paramChanged(m_stfSlider->blackPoint(), m_stfSlider->midPoint(), max); } } } void StretchToolbar::resetMTF() { m_stfSlider->setMTFParams(0, 0.5, 1); emit paramChanged(0, 0.5, 1); } void StretchToolbar::imageLoaded(Image *img) { if(m_autoStretchOnLoad->isChecked()) stretchImage(img); }