Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: auto range for min/max sliders #25

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 60 additions & 46 deletions camviewer.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1119</width>
<height>1075</height>
<width>1106</width>
<height>1070</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -798,73 +798,73 @@ Vmin\</string>
<string>Color Map</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0" colspan="2">
<widget class="QComboBox" name="comboBoxColor">
<property name="currentIndex">
<number>1</number>
</property>
<item row="0" column="3">
<widget class="QComboBox" name="comboBoxScale">
<item>
<property name="text">
<string>HSV</string>
<string>Linear Scale</string>
</property>
</item>
<item>
<property name="text">
<string>Hot</string>
<string>Log2 Scale</string>
</property>
</item>
<item>
<property name="text">
<string>Jet</string>
<string>Loge Scale</string>
</property>
</item>
<item>
<property name="text">
<string>Cool</string>
<string>Log10 Scale</string>
</property>
</item>
<item>
<property name="text">
<string>Gray</string>
<string>Exp2 Scale</string>
</property>
</item>
</widget>
</item>
<item row="0" column="3">
<widget class="QComboBox" name="comboBoxScale">
<item>
<property name="text">
<string>Linear Scale</string>
<string>Expe Scale</string>
</property>
</item>
<item>
<property name="text">
<string>Log2 Scale</string>
<string>Exp10 Scale</string>
</property>
</item>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QComboBox" name="comboBoxColor">
<property name="currentIndex">
<number>1</number>
</property>
<item>
<property name="text">
<string>Loge Scale</string>
<string>HSV</string>
</property>
</item>
<item>
<property name="text">
<string>Log10 Scale</string>
<string>Hot</string>
</property>
</item>
<item>
<property name="text">
<string>Exp2 Scale</string>
<string>Jet</string>
</property>
</item>
<item>
<property name="text">
<string>Expe Scale</string>
<string>Cool</string>
</property>
</item>
<item>
<property name="text">
<string>Exp10 Scale</string>
<string>Gray</string>
</property>
</item>
</widget>
Expand Down Expand Up @@ -898,6 +898,30 @@ Vmin\</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLineEdit" name="lineEditRangeMax">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="text">
<string>1023</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLineEdit" name="lineEditRangeMin">
<property name="sizePolicy">
Expand Down Expand Up @@ -960,34 +984,24 @@ Vmin\</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLineEdit" name="lineEditRangeMax">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
<item row="4" column="0" colspan="4">
<widget class="QCheckBox" name="grayScale">
<property name="text">
<string>Force Color Image to Grayscale</string>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QPushButton" name="pushbutton_auto_range">
<property name="text">
<string>1023</string>
<string>Auto Once</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="4">
<widget class="QCheckBox" name="grayScale">
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="checkbox_auto_range">
<property name="text">
<string>Force Color Image to Grayscale</string>
<string>Auto every frame</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -2242,7 +2256,7 @@ Vmin\</string>
<rect>
<x>0</x>
<y>0</y>
<width>1119</width>
<width>1106</width>
<height>20</height>
</rect>
</property>
Expand Down
88 changes: 57 additions & 31 deletions camviewer_ui_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ def __init__(
self.updateRoiText()
self.updateMarkerText(True, True, 0, 15)

self.max_px = 0
self.min_px = 0

sizeProjX = QSize(self.viewwidth, self.projsize)
self.ui.projH.doResize(sizeProjX)

Expand All @@ -419,14 +422,16 @@ def __init__(

self.ui.checkBoxProjAutoRange.stateChanged.connect(self.onCheckProjUpdate)

self.ui.horizontalSliderRangeMin.valueChanged.connect(
self.onSliderRangeMinChanged
self.ui.horizontalSliderRangeMin.sliderReleased.connect(
self.onSliderRangeMinReleased
)
self.ui.horizontalSliderRangeMax.valueChanged.connect(
self.onSliderRangeMaxChanged
self.ui.horizontalSliderRangeMax.sliderReleased.connect(
self.onSliderRangeMaxReleased
)
self.ui.lineEditRangeMin.returnPressed.connect(self.onRangeMinTextEnter)
self.ui.lineEditRangeMax.returnPressed.connect(self.onRangeMaxTextEnter)
self.ui.pushbutton_auto_range.pressed.connect(self.set_auto_range)
self.ui.checkbox_auto_range.stateChanged.connect(self.set_auto_range)

self.ui.horizontalSliderLens.sliderReleased.connect(self.onSliderLensReleased)
self.ui.horizontalSliderLens.valueChanged.connect(self.onSliderLensChanged)
Expand Down Expand Up @@ -1378,6 +1383,8 @@ def updateProj(self):
projXmax,
projYmin,
projYmax,
self.max_px,
self.min_px,
) = pycaqtimage.pyUpdateProj(
self.imageBuffer,
self.ui.checkBoxProjAutoRange.isChecked(),
Expand All @@ -1391,18 +1398,22 @@ def updateProj(self):
(projYmin, projYmax) = self.ui.projV.makeImage(
projXmin, projXmax, projYmin, projYmax
)

if self.ui.checkbox_auto_range.isChecked():
self.set_new_max_pixel(self.max_px)
self.set_new_min_pixel(self.min_px)
if roiMean == 0:
roiVarByMean = 0
else:
roiVarByMean = roiVar / roiMean
roi = self.ui.display_image.rectRoi.oriented()
self.ui.labelRoiInfo.setText(
"ROI Mean %-7.2f Std %-7.2f Var/Mean %-7.2f (%d,%d) W %d H %d"
"ROI Mean %-7.2f Std %-7.2f Var/Mean %-7.2f Min %d Max %d (%d,%d) W %d H %d"
% (
roiMean,
math.sqrt(roiVar),
roiVarByMean,
self.min_px,
self.max_px,
roi.x(),
roi.y(),
roi.width(),
Expand Down Expand Up @@ -2384,23 +2395,40 @@ def on_open_expert(self):
# Not handling other errors for now
subprocess.run([script])

def onSliderRangeMinChanged(self, newSliderValue):
self.ui.lineEditRangeMin.setText(str(newSliderValue))
self.iRangeMin = newSliderValue
if newSliderValue > self.iRangeMax:
self.ui.horizontalSliderRangeMax.setValue(newSliderValue)
def set_new_min_pixel(self, value: int):
value = max(0, value)
value = min(self.maxcolor, value)
self.iRangeMin = value
if value > self.iRangeMax:
self.iRangeMax = value
self.update_visible_pixel_ranges()

def set_new_max_pixel(self, value: int):
value = max(0, value)
value = min(self.maxcolor, value)
self.iRangeMax = value
if value < self.iRangeMin:
self.iRangeMin = value
self.update_visible_pixel_ranges()

def after_new_min_or_max_pixel(self):
self.setColorMap()
self.updateProj()
self.updateMiscInfo()

def onSliderRangeMaxChanged(self, newSliderValue):
self.ui.lineEditRangeMax.setText(str(newSliderValue))
self.iRangeMax = newSliderValue
if newSliderValue < self.iRangeMin:
self.ui.horizontalSliderRangeMin.setValue(newSliderValue)
self.setColorMap()
self.updateProj()
self.updateMiscInfo()
def update_visible_pixel_ranges(self):
self.ui.horizontalSliderRangeMax.setValue(self.iRangeMax)
self.ui.horizontalSliderRangeMin.setValue(self.iRangeMin)
self.ui.lineEditRangeMax.setText(str(self.iRangeMax))
self.ui.lineEditRangeMin.setText(str(self.iRangeMin))

def onSliderRangeMinReleased(self):
self.set_new_min_pixel(self.ui.horizontalSliderRangeMin.value())
self.after_new_min_or_max_pixel()

def onSliderRangeMaxReleased(self):
self.set_new_min_pixel(self.ui.horizontalSliderRangeMax.value())
self.after_new_min_or_max_pixel()

def onSliderLensChanged(self, newSliderValue):
self.ui.lineEditLens.setText(str(newSliderValue))
Expand All @@ -2424,24 +2452,22 @@ def onRangeMinTextEnter(self):
value = int(self.ui.lineEditRangeMin.text())
except Exception:
value = 0

if value < 0:
value = 0
if value > self.maxcolor:
value = self.maxcolor
self.ui.horizontalSliderRangeMin.setValue(value)
self.set_new_min_pixel(value)
self.after_new_min_or_max_pixel()

def onRangeMaxTextEnter(self):
try:
value = int(self.ui.lineEditRangeMax.text())
except Exception:
value = 0

if value < 0:
value = 0
if value > self.maxcolor:
value = self.maxcolor
self.ui.horizontalSliderRangeMax.setValue(value)
self.set_new_max_pixel(value)
self.after_new_min_or_max_pixel()

def set_auto_range(self, checked: None | Qt.CheckState = None):
if checked in (None, Qt.Checked):
self.set_new_max_pixel(self.max_px)
self.set_new_min_pixel(self.min_px)
self.after_new_min_or_max_pixel()

def onLensEnter(self):
try:
Expand Down
Loading