Skip to content
Snippets Groups Projects
Commit 7ced6897 authored by Antoine Lorence's avatar Antoine Lorence
Browse files

[Quantif] Members set to private, getters & setters added

parent effc58ea
No related branches found
No related tags found
No related merge requests found
...@@ -209,19 +209,19 @@ void MICD::codec(int nlq,int ier,int *icode,int *ireco) { ...@@ -209,19 +209,19 @@ void MICD::codec(int nlq,int ier,int *icode,int *ireco) {
void MICD::set_levels() { void MICD::set_levels() {
// Fills in iloiqu with the specified values // Fills in iloiqu with the specified values
if( quantdef->size - 1 > N_MAX_THRESHOLD || quantdef->size - 1 < 1 ) { if( quantdef->nbThresholds() > N_MAX_THRESHOLD || quantdef->nbThresholds() < 1 ) {
char buffer[255]; char buffer[255];
sprintf( buffer, "Error in MICD::set_levels:\nquantdef->GetNumThresholds() = %d", quantdef->size - 1 ); sprintf( buffer, "Error in MICD::set_levels:\nquantdef->GetNumThresholds() = %d", quantdef->nbThresholds() );
throw buffer; throw buffer;
} }
int counter; int counter;
iloiqu[0] = quantdef->size; iloiqu[0] = quantdef->nbValues();
for( counter=0; counter< quantdef->size - 1; counter++ ) { for( counter=0; counter< quantdef->nbThresholds(); counter++ ) {
iloiqu[ counter * 2 + 1 ] = quantdef->threshold[ counter ]; iloiqu[ counter * 2 + 1 ] = quantdef->threshold(counter);
iloiqu[ counter * 2 + 2 ] = quantdef->values[ counter ]; iloiqu[ counter * 2 + 2 ] = quantdef->value(counter);
} }
iloiqu[ (quantdef->size - 1) * 2 + 1 ] = iloiqu[ (quantdef->size - 1) * 2 - 1 ] + 1; iloiqu[quantdef->nbThresholds() * 2 + 1 ] = iloiqu[quantdef->nbThresholds() * 2 - 1 ] + 1;
iloiqu[ (quantdef->size - 1) * 2 + 2 ] = quantdef->values[ quantdef->size - 1 ]; iloiqu[quantdef->nbThresholds() * 2 + 2 ] = quantdef->value(quantdef->nbThresholds());
} }
string MICD::print_iloiqu() { string MICD::print_iloiqu() {
...@@ -247,9 +247,9 @@ void MICD::setQuantification( Quantification *tquantdef ) { ...@@ -247,9 +247,9 @@ void MICD::setQuantification( Quantification *tquantdef ) {
if( tquantdef == NULL ) { if( tquantdef == NULL ) {
throw "Error in MICD::setQuantDef:\ntquantdef = NULL"; throw "Error in MICD::setQuantDef:\ntquantdef = NULL";
} }
if( tquantdef->size - 1 > N_MAX_THRESHOLD || tquantdef->size - 1 < 1 ) { if( tquantdef->nbThresholds() > N_MAX_THRESHOLD || tquantdef->nbThresholds() < 1 ) {
char buffer[255]; char buffer[255];
sprintf( buffer, "Error in MICD::setQuantDef:\ntquantdef->GetNumThresholds() = %d", tquantdef->size - 1 ); sprintf( buffer, "Error in MICD::setQuantDef:\ntquantdef->GetNumThresholds() = %d", tquantdef->nbThresholds() );
throw buffer; throw buffer;
} }
quantdef = tquantdef; quantdef = tquantdef;
......
...@@ -25,8 +25,8 @@ using namespace imagein; ...@@ -25,8 +25,8 @@ using namespace imagein;
Quantification::Quantification(int size) { Quantification::Quantification(int size) {
this->size = size; this->size = size;
threshold = new int[this->size - 1]; _threshold = new int[this->size - 1];
values = new int[this->size]; _values = new int[this->size];
} }
Quantification::Quantification(std::string filename) { Quantification::Quantification(std::string filename) {
...@@ -38,19 +38,19 @@ Quantification::Quantification(std::string filename) { ...@@ -38,19 +38,19 @@ Quantification::Quantification(std::string filename) {
file >> this->size; file >> this->size;
this->size++; this->size++;
if(this->size < 2) throw exception(); if(this->size < 2) throw exception();
threshold = new int[this->size - 1]; _threshold = new int[this->size - 1];
values = new int[this->size]; _values = new int[this->size];
for(int i = 0; i < size - 1; ++i) { for(int i = 0; i < size - 1; ++i) {
double n; double n;
file >> n; file >> n;
cout << n << endl; cout << n << endl;
threshold[i] = n; _threshold[i] = n;
} }
for(int i = 0; i < size; ++i) { for(int i = 0; i < size; ++i) {
double n; double n;
file >> n; file >> n;
cout << n << endl; cout << n << endl;
values[i] = n; _values[i] = n;
} }
} }
...@@ -59,11 +59,11 @@ void Quantification::saveAs(std::string filename) { ...@@ -59,11 +59,11 @@ void Quantification::saveAs(std::string filename) {
file << "Quant_Level_File" << endl; file << "Quant_Level_File" << endl;
file << (this->size - 1) << endl; file << (this->size - 1) << endl;
for(int i = 0; i < size - 1; ++i) { for(int i = 0; i < size - 1; ++i) {
double n = threshold[i]; double n = _threshold[i];
file << n << endl; file << n << endl;
} }
for(int i = 0; i < size; ++i) { for(int i = 0; i < size; ++i) {
double n = values[i]; double n = _values[i];
file << n << endl; file << n << endl;
} }
} }
...@@ -73,14 +73,14 @@ Quantification Quantification::linearQuant(int size) { ...@@ -73,14 +73,14 @@ Quantification Quantification::linearQuant(int size) {
Quantification quant(size); Quantification quant(size);
for(int i = 0; i < size - 1; ++i) { for(int i = 0; i < size - 1; ++i) {
quant.threshold[i] = floor( (i + 1) * (float)N_MAX_THRESHOLD / size + 0.5); quant._threshold[i] = floor( (i + 1) * (float)N_MAX_THRESHOLD / size + 0.5);
} }
if(size > 0) { if(size > 0) {
quant.values[0] = floor( quant.threshold[0] / 2. + 0.5 ); quant._values[0] = floor( quant._threshold[0] / 2. + 0.5 );
quant.values[size - 1] = floor( ((float)N_MAX_THRESHOLD + 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) { for(int i = 1; i < size - 1; ++i) {
quant.values[i] = floor( (double)(quant.threshold[i] + quant.threshold[i-1]) / 2. + 0.5 ); quant._values[i] = floor( (double)(quant._threshold[i] + quant._threshold[i-1]) / 2. + 0.5 );
} }
return quant; return quant;
...@@ -101,15 +101,15 @@ Quantification Quantification::nonLinearQuant(int size, const Image* image, unsi ...@@ -101,15 +101,15 @@ Quantification Quantification::nonLinearQuant(int size, const Image* image, unsi
histogramSum += histogram[value]; histogramSum += histogram[value];
++value; ++value;
} }
quant.threshold[i] = value - 1; quant._threshold[i] = value - 1;
} }
if(size > 0) { if(size > 0) {
quant.values[0] = floor( quant.threshold[0] / 2. + 0.5 ); quant._values[0] = floor( quant._threshold[0] / 2. + 0.5 );
quant.values[size - 1] = floor( ((float)N_MAX_THRESHOLD + 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) { for(int i = 1; i < size - 1; ++i) {
quant.values[i] = floor( (double)(quant.threshold[i] + quant.threshold[i-1]) / 2. + 0.5 ); quant._values[i] = floor( (double)(quant._threshold[i] + quant._threshold[i-1]) / 2. + 0.5 );
} }
return quant; return quant;
} }
...@@ -129,45 +129,45 @@ Quantification Quantification::nonLinearQuantOptimized(int size, const Image* im ...@@ -129,45 +129,45 @@ Quantification Quantification::nonLinearQuantOptimized(int size, const Image* im
histogramSum += histogram[value]; histogramSum += histogram[value];
++value; ++value;
} }
quant.threshold[i] = value - 1; quant._threshold[i] = value - 1;
} }
if(size > 0) { if(size > 0) {
quant.values[0] = floor( quant.threshold[0] / 2. + 0.5 ); quant._values[0] = floor( quant._threshold[0] / 2. + 0.5 );
quant.values[size - 1] = floor( ((float)N_MAX_THRESHOLD + 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) { for(int i = 1; i < size - 1; ++i) {
quant.values[i] = floor( (double)(quant.threshold[i] + quant.threshold[i-1]) / 2. + 0.5 ); quant._values[i] = floor( (double)(quant._threshold[i] + quant._threshold[i-1]) / 2. + 0.5 );
} }
double som_lum = 0; double som_lum = 0;
int nb_points = 0; int nb_points = 0;
for(int j = 0; j < quant.threshold[0]; j++){ for(int j = 0; j < quant._threshold[0]; j++){
som_lum += histogram[j] * j; som_lum += histogram[j] * j;
nb_points += histogram[j]; nb_points += histogram[j];
} }
quant.values[0] = som_lum / nb_points + 0.5; quant._values[0] = som_lum / nb_points + 0.5;
for(int i = 0; i < size - 2; ++i){ for(int i = 0; i < size - 2; ++i){
som_lum = 0; som_lum = 0;
nb_points = 0; nb_points = 0;
for(int j = quant.threshold[i]; j < quant.threshold[i+1]; ++j) { for(int j = quant._threshold[i]; j < quant._threshold[i+1]; ++j) {
som_lum += histogram[j] * j; som_lum += histogram[j] * j;
nb_points += histogram[j]; nb_points += histogram[j];
} }
quant.values[i+1] = som_lum / nb_points + 0.5; quant._values[i+1] = som_lum / nb_points + 0.5;
} }
som_lum = 0; som_lum = 0;
nb_points = 0; nb_points = 0;
for(int j = quant.threshold[size-2]; j < N_MAX_THRESHOLD; ++j) { for(int j = quant._threshold[size-2]; j < N_MAX_THRESHOLD; ++j) {
som_lum += histogram[j] * j; som_lum += histogram[j] * j;
nb_points += histogram[j]; nb_points += histogram[j];
} }
quant.values[size-1] = som_lum / nb_points + 0.5; quant._values[size-1] = som_lum / nb_points + 0.5;
return quant; return quant;
} }
......
...@@ -33,20 +33,31 @@ public: ...@@ -33,20 +33,31 @@ public:
inline int valueOf(int value) const { inline int valueOf(int value) const {
for(int i = 0; i < this->size - 1; ++i) { for(int i = 0; i < this->size - 1; ++i) {
if(value < this->threshold[i]) { if(value < this->_threshold[i]) {
return this->values[i]; return this->_values[i];
} }
} }
return this->values[this->size - 1]; return this->_values[this->size - 1];
} }
inline int nbValues() {return size;}
inline int nbThresholds() {return size - 1;}
inline int value(int i) {return _values[i];}
inline void setValue(int i, int v) {_values[i] = v;}
inline int threshold(int i) {return _threshold[i];}
inline void setThreshold(int i, int v) {_threshold[i] = v;}
static Quantification linearQuant(int size); static Quantification linearQuant(int size);
static Quantification nonLinearQuant(int size, const imagein::Image *image, unsigned int c); static Quantification nonLinearQuant(int size, const imagein::Image *image, unsigned int c);
static Quantification nonLinearQuantOptimized(int size, const imagein::Image *image, unsigned int c); static Quantification nonLinearQuantOptimized(int size, const imagein::Image *image, unsigned int c);
private:
int size; int size;
int* threshold; int* _threshold;
int* values; int* _values;
}; };
class Quantifier { class Quantifier {
......
...@@ -122,7 +122,7 @@ void QuantificationDialog::open() { ...@@ -122,7 +122,7 @@ void QuantificationDialog::open() {
if(filename.isEmpty()) return; if(filename.isEmpty()) return;
Quantification q(filename.toStdString()); Quantification q(filename.toStdString());
_quantWidget->setQuantif(q); _quantWidget->setQuantif(q);
_sizeBox->setValue(q.size); _sizeBox->setValue(q.nbValues());
_quantBox->setCurrentIndex(_editorOnly ? 1 : 3); _quantBox->setCurrentIndex(_editorOnly ? 1 : 3);
} }
......
...@@ -56,12 +56,12 @@ void QuantificationOp::operator()(const imagein::Image* image, const std::map<co ...@@ -56,12 +56,12 @@ void QuantificationOp::operator()(const imagein::Image* image, const std::map<co
Image* resImg = new Image(image->getWidth(), image->getHeight(), image->getNbChannels()); Image* resImg = new Image(image->getWidth(), image->getHeight(), image->getNbChannels());
for(unsigned int c = 0; c < image->getNbChannels(); ++c) { for(unsigned int c = 0; c < image->getNbChannels(); ++c) {
Quantification quantification = dialog->getQuantif(image, c); Quantification quantification = dialog->getQuantif(image, c);
for(int i = 0; i < quantification.size; ++i) { for(int i = 0; i < quantification.nbValues(); ++i) {
cout << (int)quantification.values[i] << "."; cout << (int)quantification.value(i) << ".";
} }
cout << endl; cout << endl;
for(int i = 0; i < quantification.size-1; ++i) { for(int i = 0; i < quantification.nbThresholds(); ++i) {
cout << quantification.threshold[i] << "."; cout << quantification.threshold(i) << ".";
} }
cout << endl; cout << endl;
Quantifier quantifier = Quantifier(quantification); Quantifier quantifier = Quantifier(quantification);
......
...@@ -120,12 +120,12 @@ void QuantificationWidget::setQuantif(Quantification q) { ...@@ -120,12 +120,12 @@ void QuantificationWidget::setQuantif(Quantification q) {
void QuantificationWidget::CentralWidget::setQuantif(Quantification q) { void QuantificationWidget::CentralWidget::setQuantif(Quantification q) {
this->_nThreshold = q.size - 1; this->_nThreshold = q.nbThresholds();
for(int i = 0; i < q.size - 1; ++i) { for(int i = 0; i < q.nbThresholds(); ++i) {
_thresholdBoxes[i]->setValue(q.threshold[i]); _thresholdBoxes[i]->setValue(q.threshold(i));
} }
for(int i = 0; i < q.size; ++i) { for(int i = 0; i < q.nbValues(); ++i) {
_valueBoxes[i]->setValue(q.values[i]); _valueBoxes[i]->setValue(q.value(i));
} }
for(int i = 0; i < N_MAX_THRESHOLD; ++i) { for(int i = 0; i < N_MAX_THRESHOLD; ++i) {
_thresholdBoxes[i]->setVisible(i < _nThreshold); _thresholdBoxes[i]->setVisible(i < _nThreshold);
...@@ -142,11 +142,11 @@ Quantification QuantificationWidget::getQuantif() const { ...@@ -142,11 +142,11 @@ Quantification QuantificationWidget::getQuantif() const {
Quantification QuantificationWidget::CentralWidget::getQuantif() const { Quantification QuantificationWidget::CentralWidget::getQuantif() const {
Quantification q(_nThreshold + 1); Quantification q(_nThreshold + 1);
for(int i = 0; i < q.size - 1; ++i) { for(int i = 0; i < q.nbThresholds(); ++i) {
q.threshold[i] = _thresholdBoxes[i]->value(); q.setThreshold(i, _thresholdBoxes[i]->value());
} }
for(int i = 0; i < q.size; ++i) { for(int i = 0; i < q.nbValues(); ++i) {
q.values[i] = _valueBoxes[i]->value(); q.setValue(i, _valueBoxes[i]->value());
} }
return q; return q;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment