Skip to content
Snippets Groups Projects
Commit 0cbcb856 authored by Bigot Quentin's avatar Bigot Quentin
Browse files

fix double image entropy calculation issue

parent 1017fe4f
No related branches found
No related tags found
No related merge requests found
...@@ -39,10 +39,12 @@ DoubleEntropyOp::DoubleEntropyOp() : DoubleOperation(qApp->translate("Operations ...@@ -39,10 +39,12 @@ DoubleEntropyOp::DoubleEntropyOp() : DoubleOperation(qApp->translate("Operations
void DoubleEntropyOp::operator()(const Image_t<double>* image, const std::map<const imagein::Image_t<double>*, std::string>&) { void DoubleEntropyOp::operator()(const Image_t<double>* image, const std::map<const imagein::Image_t<double>*, std::string>&) {
double entropy = 0.; double entropy = 0.;
int min = image->min();
int max = image->max();
for(unsigned int c = 0; c < image->getNbChannels(); ++c) { for(unsigned int c = 0; c < image->getNbChannels(); ++c) {
Histogram histo = image->getHistogram(c); Histogram histo = image->getHistogram(c);
for(int i = 0; i < 256; ++i) { // for(int i = -255; i < 256 ; ++i) {
for(int i = min; i<= max; i++){
if(histo[i] > 0) { if(histo[i] > 0) {
double p = (double)histo[i] / image->getWidth() /image->getHeight(); double p = (double)histo[i] / image->getWidth() /image->getHeight();
entropy += p * log(p); entropy += p * log(p);
...@@ -52,8 +54,12 @@ void DoubleEntropyOp::operator()(const Image_t<double>* image, const std::map<co ...@@ -52,8 +54,12 @@ void DoubleEntropyOp::operator()(const Image_t<double>* image, const std::map<co
entropy = - entropy / log(2); entropy = - entropy / log(2);
outText(qApp->translate("Operations", "Entropy of the image = %1").arg(entropy).toStdString()); outText(qApp->translate("Operations", "Entropy of the image = %1").arg(entropy).toStdString());
} }
bool DoubleEntropyOp::needCurrentImg() const { bool DoubleEntropyOp::needCurrentImg() const {
return true; return true;
} }
DoubleEntropyOp::~DoubleEntropyOp() {
}
...@@ -27,6 +27,8 @@ class DoubleEntropyOp : public DoubleOperation ...@@ -27,6 +27,8 @@ class DoubleEntropyOp : public DoubleOperation
public: public:
DoubleEntropyOp(); DoubleEntropyOp();
virtual ~DoubleEntropyOp();
void operator()(const imagein::Image_t<double>*, const std::map<const imagein::Image_t<double>*, std::string>&); void operator()(const imagein::Image_t<double>*, const std::map<const imagein::Image_t<double>*, std::string>&);
bool needCurrentImg() const; bool needCurrentImg() const;
......
...@@ -57,3 +57,6 @@ void EntropyOp::operator()(const Image* image, const std::map<const imagein::Ima ...@@ -57,3 +57,6 @@ void EntropyOp::operator()(const Image* image, const std::map<const imagein::Ima
bool EntropyOp::needCurrentImg() const { bool EntropyOp::needCurrentImg() const {
return true; return true;
} }
EntropyOp::~EntropyOp() {
}
...@@ -27,6 +27,8 @@ class EntropyOp : public Operation ...@@ -27,6 +27,8 @@ class EntropyOp : public Operation
public: public:
EntropyOp(); EntropyOp();
virtual ~EntropyOp();
void operator()(const imagein::Image*, const std::map<const imagein::Image*, std::string>&); void operator()(const imagein::Image*, const std::map<const imagein::Image*, std::string>&);
bool needCurrentImg() const; bool needCurrentImg() const;
......
Subproject commit 9376ae7717171c4a1e7ab4027f2d656742689763 Subproject commit 8f5e49b95200fc47fffcb06bf7a2a612ea72464e
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