Skip to content
Snippets Groups Projects
Commit e3335bb6 authored by Provot Bertrand's avatar Provot Bertrand
Browse files

Merge branch 'qb2017' of github.com:eiimage/eiimage into qb2017

parents f6018a3a ff591c45
No related branches found
No related tags found
No related merge requests found
......@@ -98,24 +98,26 @@ void QuantificationDialog::methodChanged(int method) {
this->adjustSize();
}
Quantification QuantificationDialog::getQuantif(const Image* image, unsigned int c, std::string &to_print) {
Quantification QuantificationDialog::getQuantif(const Image* image, unsigned int c, std::string &to_print, bool * checkOptiQuant) {
*checkOptiQuant = false;
int size = _sizeBox->value();
if(_editorOnly) return Quantification::linearQuant(size);
switch(_quantBox->currentIndex()) {
case 1:
to_print = "Quantification non lineaire a valeur centrees :";
to_print = "Quantification non lineaire a valeurs centrees :";
return Quantification::nonLinearQuant(size, image, c);
break;
case 2:
to_print = "Quantification non lineaire a moyennes : ";
to_print = "Quantification non lineaire a valeurs moyennes : ";
return Quantification::nonLinearQuantOptimized(size, image, c);
break;
case 3:
to_print = "Quantification personnalisée :";
to_print = "Quantification personnalisee :";
return _quantWidget->getQuantif();
break;
case 4:
to_print = "Quantification LloydMax :";
*checkOptiQuant = true;
return Quantification::lloydMaxQuant(size, image, c);
break;
......
......@@ -33,7 +33,7 @@ class QuantificationDialog : public QDialog
public:
enum QuantMethod {LinearQuant, NonLinearQuant, NonLinearQuantOptimized};
explicit QuantificationDialog(QWidget *parent = 0, QString imgName = QString());
Quantification getQuantif(const imagein::Image *image, unsigned int c, std::string &);
Quantification getQuantif(const imagein::Image *image, unsigned int c, std::string &, bool * checkOptiQuant);
Quantification getQuantif();
signals:
......
......@@ -78,10 +78,76 @@ string QuantificationOp::quantificationOpLog(unsigned int c, Quantification * qu
return output_msg;
}
string checkOptimumQuantizier(const imagein::Image* image, Quantification * quant, unsigned int c){
float baricenter;
float valueCenter;
float centroid = 0.0;
float neighbor = 0.0;
int som_lum = 0;
int nb_points = 0;
char buffer[100];
Histogram hist = image->getHistogram(c);
for (int j=1; j<quant->nbThresholds();j++){
som_lum = 0;
nb_points = 0;
//Calcul des baricentres entre deux seuils
for(int i= quant->threshold(j-1); i <= quant->threshold(j); i++){
som_lum += hist[i]*i;
nb_points += hist[i];
}
baricenter = som_lum/nb_points;
centroid += abs( baricenter - quant->value(j) ) /( quant->threshold(j) - quant->threshold(j-1) ) * 100;
}
//cas spécial
if( quant->nbValues() == 2){
som_lum = 0;
nb_points = 0;
for(int i= 0; i <= quant->threshold(0); i++){
som_lum += hist[i]*i;
nb_points += hist[i];
}
baricenter = som_lum/nb_points;
centroid = abs( baricenter - quant->value(0) ) /( quant->threshold(0) ) * 100;
som_lum = 0;
nb_points = 0;
for(int i= quant->threshold(0); i <= 255 ; i++){
som_lum += hist[i]*i;
nb_points += hist[i];
}
baricenter = som_lum/nb_points;
centroid += abs( baricenter - quant->value(1) ) / ( 255 - quant->threshold(0) ) * 100;
}
for(int i = 0; i<quant->nbThresholds(); i++){
valueCenter = ( quant->value(i) + quant->value(i+1) ) / 2 ;
neighbor += abs( valueCenter - quant->threshold(i) ) / ( quant->value(i) - quant->value(i+1) ) * 100;
}
neighbor = neighbor / quant->nbThresholds();
if( quant->nbValues() == 2) centroid = centroid / 2;
else centroid = centroid / ( quant->nbThresholds() - 1 );
sprintf(buffer, "Canal : %d Centroïd : %.2f % Plus proche voisin : %.2f %\n", c, (100-centroid), (100-neighbor));
return buffer;
}
void QuantificationOp::operator()(const imagein::Image* image, const std::map<const imagein::Image*, std::string>& imgList) {
string quantType;
string output_msg ="" ;
string output_msg = "";
string optiQuant;
bool checkOptiQuant;
QuantificationDialog* dialog;
if(image != NULL) {
......@@ -104,7 +170,7 @@ void QuantificationOp::operator()(const imagein::Image* image, const std::map<co
for(unsigned int c = 0; c < image->getNbChannels(); ++c) {
Quantification quantification = dialog->getQuantif(image, c, quantType);
Quantification quantification = dialog->getQuantif(image, c, quantType, &checkOptiQuant);
//Generate the text to print in the information window
output_msg += quantificationOpLog(c, &quantification);
......@@ -117,7 +183,20 @@ void QuantificationOp::operator()(const imagein::Image* image, const std::map<co
resImg->setPixelAt(i, j, c, quantification.valueOf(value));
}
}
if(checkOptiQuant)
optiQuant += checkOptimumQuantizier(image, &quantification, c);
}
outText(quantType);
outText(output_msg);
if(checkOptiQuant){
outText("Respect des conditions du quantifieur optimal : ");
outText(optiQuant);
}
outImage(resImg, qApp->translate("QuantificationOp", "quantified").toStdString());
QString windowName;
QString imgName;
......@@ -139,7 +218,6 @@ void QuantificationOp::operator()(const imagein::Image* image, const std::map<co
else{
imgName = QString("");
}
outText(output_msg);
outImage(resImg, imgName.toStdString() + windowName.toStdString());
}
......
This diff is collapsed.
This diff is collapsed.
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