diff --git a/app/Operations/Quantification.cpp b/app/Operations/Quantification.cpp index 249d941e64deb7af8e4bccf4ab6af863849e7c26..c9a084716baa359be1682c73725d3b9cc9e3daaf 100644 --- a/app/Operations/Quantification.cpp +++ b/app/Operations/Quantification.cpp @@ -26,7 +26,7 @@ using namespace imagein; Quantification::Quantification(int size_) { this->size = size_; threshold = new int[this->size - 1]; - values = new imagein::Image::depth_t[this->size]; + values = new int[this->size]; } Quantification::Quantification(std::string filename) { @@ -39,7 +39,7 @@ Quantification::Quantification(std::string filename) { this->size++; if(this->size < 2) throw exception(); threshold = new int[this->size - 1]; - values = new imagein::Image::depth_t[this->size]; + values = new int[this->size]; for(int i = 0; i < size - 1; ++i) { double n; file >> n; @@ -68,9 +68,8 @@ void Quantification::saveAs(std::string filename) { } } - Quantifier::Quantifier(Quantification quant) { - for(int i = 0; i < 256; ++i) { + for(int i = 0; i < N_MAX_THRESHOLD; ++i) { values[i] = quant.valueOf(i); } } @@ -80,11 +79,11 @@ Quantification Quantification::linearQuant(int size) { Quantification quant(size); for(int i = 0; i < size - 1; ++i) { - quant.threshold[i] = floor( (i + 1) * 256. / size + 0.5); + quant.threshold[i] = floor( (i + 1) * (float)N_MAX_THRESHOLD / size + 0.5); } if(size > 0) { quant.values[0] = floor( quant.threshold[0] / 2. + 0.5 ); - quant.values[size - 1] = floor( (256. + quant.threshold[size - 2]) / 2. + 0.5 ); + quant.values[size - 1] = floor( ((float)N_MAX_THRESHOLD + quant.threshold[size - 2]) / 2. + 0.5 ); } for(int i = 1; i < size - 1; ++i) { quant.values[i] = floor( (double)(quant.threshold[i] + quant.threshold[i-1]) / 2. + 0.5 ); @@ -93,7 +92,6 @@ Quantification Quantification::linearQuant(int size) { return quant; } - Quantification Quantification::nonLinearQuant(int size, const Image* image, unsigned int c) { Quantification quant(size); @@ -114,7 +112,7 @@ Quantification Quantification::nonLinearQuant(int size, const Image* image, unsi if(size > 0) { quant.values[0] = floor( quant.threshold[0] / 2. + 0.5 ); - quant.values[size - 1] = floor( (256. + quant.threshold[size - 2]) / 2. + 0.5 ); + quant.values[size - 1] = floor( ((float)N_MAX_THRESHOLD + quant.threshold[size - 2]) / 2. + 0.5 ); } for(int i = 1; i < size - 1; ++i) { quant.values[i] = floor( (double)(quant.threshold[i] + quant.threshold[i-1]) / 2. + 0.5 ); @@ -142,7 +140,7 @@ Quantification Quantification::nonLinearQuantOptimized(int size, const Image* im if(size > 0) { quant.values[0] = floor( quant.threshold[0] / 2. + 0.5 ); - quant.values[size - 1] = floor( (256. + quant.threshold[size - 2]) / 2. + 0.5 ); + quant.values[size - 1] = floor( ((float)N_MAX_THRESHOLD + quant.threshold[size - 2]) / 2. + 0.5 ); } for(int i = 1; i < size - 1; ++i) { quant.values[i] = floor( (double)(quant.threshold[i] + quant.threshold[i-1]) / 2. + 0.5 ); @@ -157,10 +155,8 @@ Quantification Quantification::nonLinearQuantOptimized(int size, const Image* im nb_points += histogram[j]; } - quant.values[0] = som_lum / nb_points + 0.5; - for(int i = 0; i < size - 2; ++i){ som_lum = 0; nb_points = 0; @@ -171,10 +167,9 @@ Quantification Quantification::nonLinearQuantOptimized(int size, const Image* im quant.values[i+1] = som_lum / nb_points + 0.5; } - som_lum = 0; nb_points = 0; - for(int j = quant.threshold[size-2]; j < 256; ++j) { + for(int j = quant.threshold[size-2]; j < N_MAX_THRESHOLD; ++j) { som_lum += histogram[j] * j; nb_points += histogram[j]; } diff --git a/app/Operations/Quantification.h b/app/Operations/Quantification.h index 2875efc4facca89955adf84a729aae98acaec00c..67d71aad0399c4fc8c3861fea9d3dd4b5a82fc5a 100644 --- a/app/Operations/Quantification.h +++ b/app/Operations/Quantification.h @@ -30,9 +30,12 @@ struct Quantification { static Quantification nonLinearQuantOptimized(int size, const imagein::Image *image, unsigned int c); explicit Quantification(std::string filename); + void saveAs(std::string filename); + explicit Quantification(int size_); - inline imagein::Image::depth_t valueOf(imagein::Image::depth_t value) const { + + inline int valueOf(int value) const { for(int i = 0; i < this->size - 1; ++i) { if(value < this->threshold[i]) { return this->values[i]; @@ -42,16 +45,16 @@ struct Quantification { } int size; int* threshold; - imagein::Image::depth_t* values; + int* values; }; struct Quantifier { Quantifier(Quantification quant); - inline imagein::Image::depth_t valueOf(imagein::Image::depth_t value) { + inline int valueOf(imagein::Image::depth_t value) { return this->values[value]; } private: - imagein::Image::depth_t values[256]; + int values[N_MAX_THRESHOLD]; }; #endif // QUANTIFICATION_H diff --git a/app/Operations/QuantificationDialog.cpp b/app/Operations/QuantificationDialog.cpp index 3c35519c9c4a0227f0fb13f35572a1dbaad4c443..8948eca620afad3fb23a7d4653399a0fee23e2bf 100644 --- a/app/Operations/QuantificationDialog.cpp +++ b/app/Operations/QuantificationDialog.cpp @@ -49,7 +49,6 @@ QuantificationDialog::QuantificationDialog(QWidget *parent, QString imgName) : _sizeBox->setRange(2, 256); _sizeBox->setValue(2); - _quantBox = new QComboBox(); _quantBox->addItem(tr("Linear with centered value")); if(!_editorOnly) { @@ -91,14 +90,13 @@ QuantificationDialog::QuantificationDialog(QWidget *parent, QString imgName) : } } - void QuantificationDialog::methodChanged(int method) { _editorWidget->setVisible((_editorOnly && method == 1) || (!_editorOnly && method == 3)); _saveButton->setEnabled(_editorOnly || method==3 || method == 0); this->adjustSize(); } -Quantification QuantificationDialog::getQuantif(const Image* image, unsigned int c) { +Quantification QuantificationDialog::getQuantif(const Image* image, unsigned int c) { int size = _sizeBox->value(); if(_editorOnly) return Quantification::linearQuant(size); switch(_quantBox->currentIndex()) { diff --git a/app/Operations/QuantificationDialog.h b/app/Operations/QuantificationDialog.h index 72e1c375583eb1233c25a8bb3d8012b0bc0705a2..b88fd57ec6fe8013c41fe60bab47cb6db046c574 100644 --- a/app/Operations/QuantificationDialog.h +++ b/app/Operations/QuantificationDialog.h @@ -26,6 +26,7 @@ #include "Quantification.h" #include "QuantificationWidget.h" #include <QPushButton> + class QuantificationDialog : public QDialog { Q_OBJECT diff --git a/app/Operations/QuantificationWidget.cpp b/app/Operations/QuantificationWidget.cpp index aa6a6f4f986554c9a7446c839bc790e68351c740..076ffabd2f404b0964203d1e1acf49afb8bca4ca 100644 --- a/app/Operations/QuantificationWidget.cpp +++ b/app/Operations/QuantificationWidget.cpp @@ -56,21 +56,21 @@ QuantificationWidget::CentralWidget::CentralWidget(QWidget *parent) : _thresholdBoxes[i] = new QSpinBox(this); _thresholdBoxes[i]->setFixedSize(64, 28); _thresholdBoxes[i]->move(QPoint((_firstWidth-64)/2, i * 32 + 16 + _yOffset)); - _thresholdBoxes[i]->setRange(0, 255); + _thresholdBoxes[i]->setRange(-254, 255); if(i >= _nThreshold) _thresholdBoxes[i]->setVisible(false); } for(int i = 0; i < N_MAX_THRESHOLD + 1; ++i) { _valueBoxes[i] = new QSpinBox(this); - _valueBoxes[i]->setRange(0, 255); _valueBoxes[i]->setFixedSize(64, 28); _valueBoxes[i]->move(QPoint(_firstWidth + 32 + (_secondWidth-64)/2, i * 32 + _yOffset)); + _valueBoxes[i]->setRange(-254, 255); if(i > _nThreshold) _valueBoxes[i]->setVisible(false); } // editorLayout->addWidget(_valueBoxes[32], 32, 1); // this->setFixedSize(_firstWidth + 32 + _secondWidth, _nThreshold * 32 + _yOffset + 28); } -void QuantificationWidget::CentralWidget::paintEvent (QPaintEvent *e) +void QuantificationWidget::CentralWidget::paintEvent(QPaintEvent *) { QPainter *painter = new QPainter (this); QPen pen(Qt::darkGray, 2, Qt::DashLine); @@ -82,13 +82,13 @@ void QuantificationWidget::CentralWidget::paintEvent (QPaintEvent *e) } painter->end (); } + QSize QuantificationWidget::sizeHint () const { return this->widget()->size(); } + QSize QuantificationWidget::CentralWidget::sizeHint () const { return QSize(_firstWidth + 32 + _secondWidth, _nThreshold * 32 + _yOffset + 28); - - } void QuantificationWidget::setNbThreshold(int n) { @@ -103,7 +103,6 @@ void QuantificationWidget::setNbThreshold(int n) { this->parentWidget()->parentWidget()->adjustSize(); } - void QuantificationWidget::CentralWidget::setNbThreshold(int n) { this->_nThreshold = min(N_MAX_THRESHOLD, n); for(int i = 0; i < N_MAX_THRESHOLD; ++i) { @@ -118,6 +117,7 @@ void QuantificationWidget::CentralWidget::setNbThreshold(int n) { void QuantificationWidget::setQuantif(Quantification q) { this->_centralWidget->setQuantif(q); } + void QuantificationWidget::CentralWidget::setQuantif(Quantification q) { this->_nThreshold = q.size - 1; @@ -136,8 +136,6 @@ void QuantificationWidget::CentralWidget::setQuantif(Quantification q) { this->updateGeometry(); } - - Quantification QuantificationWidget::getQuantif() const { return _centralWidget->getQuantif(); }