From ebb3348e7c9cec93ba70c5c313bb9e5c5293c909 Mon Sep 17 00:00:00 2001 From: Christine Kim <125395064+chkim-usgs@users.noreply.github.com> Date: Fri, 5 Apr 2024 15:58:16 -0400 Subject: [PATCH] Added min/max type selection option (#5455) --- CHANGELOG.md | 1 + .../qisis/objs/StretchTool/StretchTool.cpp | 79 ++++++++++++++++++- isis/src/qisis/objs/StretchTool/StretchTool.h | 2 + 3 files changed, 80 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76c7508532..8863b45c23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ release. - Added new Hayabusa2 translation for `SpacecraftName` to accept `HAYABUSA2` [#5395](https://github.com/DOI-USGS/ISIS3/issues/5395) - Added ALLOWERROR parameter to campt [#5393](https://github.com/DOI-USGS/ISIS3/pull/5393) - OSIRIS-REx Tagcams instrument support, tests, and test data added [#5424](https://github.com/DOI-USGS/ISIS3/issues/5424) +- Added min/max type drop-down selection option in QView's Stretch tool [#5289](https://github.com/DOI-USGS/ISIS3/issues/5289) ## [8.1.0] - 2024-01-08 diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index 4f0aec0a72..3ee41848c3 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -183,6 +183,29 @@ namespace Isis { connect(m_stretchBandComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(stretchBandChanged(int))); + // Create drop-down selection option to set min/max type + p_minMaxTypeSelection = new QComboBox(); + p_minMaxTypeSelection->setToolTip("Min/Max Type"); + text = + "Function: Select the minimum & maximum value types to \ + set the stretch to. The three options are: \ +
- Best: (default) The better of the absolute min/max or the \ + Chebyshev min/max. The better value is considered the value \ + closest to the mean. \ +
- Absolute: The absolute min/max value of all valid pixels. \ +
- Chebyshev: The min/max value such that a certain percentage \ + of data will fall within K standard deviations of the average \ + (Chebyshev's Theorem). It can be used to obtain a value that \ + does not include statistical outliers. \ +
Hint: Percentages are set to mininum of 0.5 and \ + maximum of 99.5."; + p_minMaxTypeSelection->setWhatsThis(text); + p_minMaxTypeSelection->addItem("Best", 0); + p_minMaxTypeSelection->addItem("Absolute", 1); + p_minMaxTypeSelection->addItem("Chebyshev", 2); + + connect(p_minMaxTypeSelection, SIGNAL(currentIndexChanged(int)), this, SLOT(changeStretch())); + QDoubleValidator *dval = new QDoubleValidator(hbox); m_stretchMinEdit = new QLineEdit(hbox); m_stretchMinEdit->setValidator(dval); @@ -306,6 +329,7 @@ namespace Isis { layout->addWidget(m_globalButton); layout->addWidget(m_stretchRegionalButton); layout->addWidget(m_stretchBandComboBox); + layout->addWidget(p_minMaxTypeSelection); layout->addWidget(m_stretchMinEdit); layout->addWidget(m_stretchMaxEdit); layout->addWidget(advancedButton); @@ -1035,6 +1059,9 @@ namespace Isis { MdiCubeViewport *cvp = cubeViewport(); if(cvp == NULL) return; + // Set the min/max based on selected type + stretchMinMaxType(cvp); + // Make sure the user didn't enter bad min/max and if so fix it double min = m_stretchMinEdit->text().toDouble(); double max = m_stretchMaxEdit->text().toDouble(); @@ -1088,6 +1115,54 @@ namespace Isis { stretchChanged(); } + /** + * Sets stretch for current band in active viewport given + * the min/max type selection. + */ + void StretchTool::stretchMinMaxType(CubeViewport *cvp) { + // Get current band + int bandId = m_stretchBandComboBox->currentIndex(); + int bandNum = cvp->grayBand(); + if(bandId == (int)Red) { + bandNum = cvp->redBand(); + } + else if(bandId == (int)Green) { + bandNum = cvp->greenBand(); + } + else if(bandId == (int)Blue) { + bandNum = cvp->blueBand(); + } + + // Get current band statistics + Statistics stats = statsFromCube(cvp->cube(), bandNum); + + // Set min/max given ComboBox selection + int minMaxIndex = p_minMaxTypeSelection->currentIndex(); + double selectedMin = 0; + double selectedMax = 0; + + if (minMaxIndex == 0) { + // Best + selectedMin = stats.BestMinimum(); + selectedMax = stats.BestMaximum(); + } else if (minMaxIndex == 1) { + // Absolute + selectedMin = stats.Minimum(); + selectedMax = stats.Maximum(); + } else if (minMaxIndex == 2) { + // Chebyshev + selectedMin = stats.ChebyshevMinimum(); + selectedMax = stats.ChebyshevMaximum(); + } + + QString qMin = QString::number(selectedMin); + QString qMax = QString::number(selectedMax); + + // Set the min/max text + m_stretchMinEdit->setText(qMin); + m_stretchMaxEdit->setText(qMax); + } + /** * This methods shows and updates the advanced dialog. @@ -1526,7 +1601,7 @@ namespace Isis { cube->read(brick); hist.AddData(brick.DoubleBuffer(), cube->sampleCount()); } - + return hist; } @@ -1541,7 +1616,7 @@ namespace Isis { Histogram StretchTool::histFromBuffer(ViewportBuffer *buffer) { Statistics stats = statsFromBuffer(buffer, buffer->bufferXYRect()); return histFromBuffer(buffer, buffer->bufferXYRect(), - stats.BestMinimum(), stats.BestMaximum()); + stats.BestMinimum(), stats.BestMaximum()); } diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.h b/isis/src/qisis/objs/StretchTool/StretchTool.h index 8e38ffe472..3ebd94e715 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.h +++ b/isis/src/qisis/objs/StretchTool/StretchTool.h @@ -177,6 +177,7 @@ namespace Isis { private: void stretchRect(CubeViewport *cvp, QRect rect); + void stretchMinMaxType(CubeViewport *cvp); private: AdvancedStretchDialog *m_advancedStretch; //!< The advanced dialog @@ -192,6 +193,7 @@ namespace Isis { QAction *m_copyBands; //!< Copy band stretch action QComboBox *m_stretchBandComboBox; //!< Stretch combo box + QComboBox *p_minMaxTypeSelection; //!< Min/Max type combo box QLineEdit *m_stretchMinEdit; //!< Min. line edit QLineEdit *m_stretchMaxEdit; //!< Max. line edit