Skip to content
Permalink
Browse files

raster single band gray cumulative pixel count cut

  • Loading branch information
blazek committed Jul 20, 2012
1 parent 193c3c2 commit c517a90cdd2d82855dfd5cf8d7e39eb4c91f50e2
@@ -75,6 +75,36 @@ bool QgsRasterRendererWidget::bandMinMax( LoadMinMaxAlgo loadAlgo, int band, dou
{
mRasterLayer->computeMinimumMaximumFromLastExtent( band, minMaxValues );
}
else if ( loadAlgo == CumulativeCut )
{
// Currently 2 - 98% cumulative pixel count cut
bool myIgnoreOutOfRangeFlag = true;
bool myThoroughBandScanFlag = false;
mRasterLayer->populateHistogram( band, RASTER_HISTOGRAM_BINS, myIgnoreOutOfRangeFlag, myThoroughBandScanFlag );

QgsRasterBandStats myRasterBandStats = mRasterLayer->bandStatistics( band );
double myBinXStep = myRasterBandStats.range / RASTER_HISTOGRAM_BINS;
int myCount = 0;
int myMinCount = ( int ) qRound( 0.02 * myRasterBandStats.elementCount );
int myMaxCount = ( int ) qRound( 0.98 * myRasterBandStats.elementCount );
bool myMinFound = false;
QgsDebugMsg( QString( "RASTER_HISTOGRAM_BINS = %1 range = %2 minimumValue = %3 myBinXStep = %4" ).arg( RASTER_HISTOGRAM_BINS ).arg( myRasterBandStats.range ).arg( myRasterBandStats.minimumValue ).arg( myBinXStep ) );
for ( int myBin = 0; myBin < RASTER_HISTOGRAM_BINS; myBin++ )
{
int myBinValue = myRasterBandStats.histogramVector->value( myBin );
myCount += myBinValue;
if ( !myMinFound && myCount > myMinCount )
{
minMaxValues[0] = myRasterBandStats.minimumValue + myBin * myBinXStep;
myMinFound = true;
}
if ( myCount > myMaxCount )
{
minMaxValues[1] = myRasterBandStats.minimumValue + myBin * myBinXStep;
break;
}
}
}
else
{
return false;
@@ -33,7 +33,8 @@ class GUI_EXPORT QgsRasterRendererWidget: public QWidget
{
Estimate,
Actual,
CurrentExtent
CurrentExtent,
CumulativeCut // 2 - 98% cumulative cut
};

virtual QgsRasterRenderer* renderer() = 0;
@@ -98,18 +98,23 @@ void QgsSingleBandGrayRendererWidget::on_mLoadPushButton_clicked()
{
ok = bandMinMax( CurrentExtent, band, minMaxValues );
}

if ( ok )
else if ( mCumulativeCut->isChecked() )
{
mMinLineEdit->setText( QString::number( minMaxValues[0] ) );
mMaxLineEdit->setText( QString::number( minMaxValues[1] ) );
ok = bandMinMax( CumulativeCut, band, minMaxValues );
}
else if ( mUseStdDevRadioButton->isChecked() )
{
QgsRasterBandStats rasterBandStats = mRasterLayer->bandStatistics( band );
double diff = mStdDevSpinBox->value() * rasterBandStats.stdDev;
minMaxValues[0] = rasterBandStats.mean - diff;
minMaxValues[1] = rasterBandStats.mean + diff;
ok = true;
}

if ( ok )
{
mMinLineEdit->setText( QString::number( minMaxValues[0] ) );
mMaxLineEdit->setText( QString::number( minMaxValues[1] ) );
}
else
{
@@ -70,7 +70,7 @@
</property>
</widget>
</item>
<item row="4" column="1" colspan="4">
<item row="5" column="1" colspan="4">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -96,14 +96,14 @@
</property>
</spacer>
</item>
<item row="3" column="0" colspan="3">
<item row="4" column="0" colspan="3">
<widget class="QRadioButton" name="mUseStdDevRadioButton">
<property name="text">
<string>Use standard deviation</string>
</property>
</widget>
</item>
<item row="3" column="3">
<item row="4" column="3">
<widget class="QDoubleSpinBox" name="mStdDevSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@@ -116,7 +116,7 @@
</property>
</widget>
</item>
<item row="3" column="4">
<item row="4" column="4">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@@ -129,13 +129,33 @@
</property>
</spacer>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QPushButton" name="mLoadPushButton">
<property name="text">
<string>Load</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QRadioButton" name="mCumulativeCut">
<property name="text">
<string>2 - 98% cumulative pixel count cut</string>
</property>
</widget>
</item>
<item row="3" column="2" colspan="3">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>

0 comments on commit c517a90

Please sign in to comment.
You can’t perform that action at this time.