diff --git a/app/docks/FramePropertiesDock.cpp b/app/docks/FramePropertiesDock.cpp index 4bc059c..c08b425 100644 --- a/app/docks/FramePropertiesDock.cpp +++ b/app/docks/FramePropertiesDock.cpp @@ -204,6 +204,11 @@ FramePropertiesDock::FramePropertiesDock( QWidget* parent, bool* pbMainPlaySwitc labelMedianValue = new QLabel; labelMedianValue->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); + QLabel* entropyLabel = new QLabel( tr( "Entropy:" ) ); + entropyLabel->setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); + labelEntropyValue = new QLabel; + labelEntropyValue->setAlignment( Qt::AlignRight | Qt::AlignVCenter ); + QLabel* percentileLabel = new QLabel( tr( "Percentile:" ) ); percentileLabel->setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); labelPercentileValue = new QLabel; @@ -225,6 +230,8 @@ FramePropertiesDock::FramePropertiesDock( QWidget* parent, bool* pbMainPlaySwitc statisticsLayout->addWidget( labelStdDevValue, gridRow++, 1 ); statisticsLayout->addWidget( medianLabel, gridRow, 0 ); statisticsLayout->addWidget( labelMedianValue, gridRow++, 1 ); + statisticsLayout->addWidget( entropyLabel, gridRow, 0 ); + statisticsLayout->addWidget( labelEntropyValue, gridRow++, 1 ); QGroupBox* statisticsGroup = new QGroupBox( tr( "Statistics" ) ); statisticsGroup->setLayout( statisticsLayout ); @@ -474,6 +481,9 @@ void FramePropertiesDock::updateStatistiques() double median = frame->getMedian( channel, min, max ); labelMedianValue->setText( value.setNum( median, 'f', 1 ) ); + double entropy = frame->getEntropy( channel, min, max ); + labelEntropyValue->setText( value.setNum( entropy, 'f', 2 ) ); + double percentile = ( pixels > 0 ? ( 100.0 * counts / pixels ) : 0.0 ); labelPercentileValue->setText( value.setNum( percentile, 'f', 1 ) ); } diff --git a/app/docks/FramePropertiesDock.h b/app/docks/FramePropertiesDock.h index e0acc88..5d90504 100644 --- a/app/docks/FramePropertiesDock.h +++ b/app/docks/FramePropertiesDock.h @@ -76,6 +76,7 @@ private: QLabel* labelMeanValue; QLabel* labelStdDevValue; QLabel* labelMedianValue; + QLabel* labelEntropyValue; QLabel* labelPercentileValue; QLabel* colorsLabel; diff --git a/app/widgets/HistogramWidget.cpp b/app/widgets/HistogramWidget.cpp index efd1c41..4afe66b 100644 --- a/app/widgets/HistogramWidget.cpp +++ b/app/widgets/HistogramWidget.cpp @@ -940,6 +940,10 @@ void HistogramWidget::paintEvent( QPaintEvent* ) double median = frame->getMedian( m_channelType, 0, frame->getNumHistogramSegment() - 1 ); tipText += value.setNum( median, 'f', 1 ) + cellEnd; + tipText += cellBeg + tr( "Entropy:" ) + cellMid; + double entropy = frame->getEntropy( m_channelType, 0, frame->getNumHistogramSegment() - 1 ); + tipText += value.setNum( entropy, 'f', 2 ) + cellEnd; + tipText += cellBeg + tr( "Percent:" ) + cellMid; double percentile = ( pixels > 0 ? ( 100.0 * counts / pixels ) : 0.0 ); tipText += value.setNum( percentile, 'f', 1 ) + cellEnd; diff --git a/lib/CalypFrame.cpp b/lib/CalypFrame.cpp index a6ddf4f..4591db3 100644 --- a/lib/CalypFrame.cpp +++ b/lib/CalypFrame.cpp @@ -1132,6 +1132,32 @@ double CalypFrame::getHistogramValue( unsigned channel, unsigned int bin ) return d->m_puiHistogram[indexStart + bin]; } +double CalypFrame::getEntropy( unsigned channel, unsigned int start, unsigned int end ) +{ + if( !d->m_bHasHistogram ) + return 0; + + channel = d->getRealHistogramChannel( channel ); + if( channel < 0 ) + return 0; + + int indexStart = channel * d->m_uiHistoSegments; + double numValues = getNumPixelsRange( channel, start, end ); + double entropy = 0.0; + + for( unsigned b = start; b < end; b++ ) + { + if (d->m_puiHistogram[indexStart + b] == 0) + continue; + + double prob = d->m_puiHistogram[indexStart + b] / numValues; + + entropy -= prob * log2(prob); + } + + return entropy; +} + /* ************************************************************** * interface to other libs diff --git a/lib/CalypFrame.h b/lib/CalypFrame.h index ce35178..4272ebe 100644 --- a/lib/CalypFrame.h +++ b/lib/CalypFrame.h @@ -382,6 +382,7 @@ public: double getHistogramValue( unsigned channel, unsigned int bin ); unsigned int getNEBins( unsigned channel ); int getNumHistogramSegment(); + double getEntropy( unsigned channel, unsigned int start, unsigned int end ); /** * interface with OpenCV lib