Skip to content
Snippets Groups Projects
Commit 5531580d authored by Sacha Percot-Tétu's avatar Sacha Percot-Tétu
Browse files

Added entropy operation

parent 0661fd74
No related branches found
No related tags found
No related merge requests found
/*
* Copyright 2011-2012 INSA Rennes
*
* This file is part of EIImage.
*
* EIImage is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EIImage is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EIImage. If not, see <http://www.gnu.org/licenses/>.
*/
#include "EntropyOp.h"
#include "../Tools.h"
#include <Image.h>
using namespace std;
using namespace imagein;
EntropyOp::EntropyOp() : Operation(Tools::tr("Calcul d'entropie").toStdString())
{
}
void EntropyOp::operator()(const imagein::Image* image, const std::map<const imagein::Image*, std::string>&) {
double entropy = 0.;
for(unsigned int c = 0; c < image->getNbChannels(); ++c) {
Histogram histo = image->getHistogram(c);
for(int i = 0; i < 256; ++i) {
if(histo[i] > 0) {
double p = (double)histo[i] / image->getWidth() /image->getHeight();
entropy += p * log(p);
}
}
}
entropy = - entropy / log(2);
outText(Tools::tr("Entropy of the image = %1").arg(entropy).toStdString());
}
bool EntropyOp::needCurrentImg() const {
return true;
}
/*
* Copyright 2011-2012 INSA Rennes
*
* This file is part of EIImage.
*
* EIImage is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EIImage is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EIImage. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ENTROPYOP_H
#define ENTROPYOP_H
#include <Operation.h>
class EntropyOp : public Operation
{
public:
EntropyOp();
void operator()(const imagein::Image*, const std::map<const imagein::Image*, std::string>&);
bool needCurrentImg() const;
};
#endif // ENTROPYOP_H
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