Skip to content

Commit

Permalink
improve contour visualization
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Oct 7, 2019
1 parent d889b6e commit a01df64
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 25 deletions.
18 changes: 12 additions & 6 deletions shapeout2/gui/quick_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def __init__(self, *args, **kwargs):
self.on_event_scatter_update)
self.checkBox_zoom_roi.stateChanged.connect(
self.on_event_scatter_update)
self.checkBox_auto_contrast.stateChanged.connect(
self.on_event_scatter_update)

# value changed signals for plot
self.signal_widgets = [self.checkBox_downsample,
Expand Down Expand Up @@ -96,7 +98,8 @@ def __getstate__(self):
"isoelastics enabled": self.checkBox_isoelastics.isChecked(),
"filters": self.filters,
}
event = {"contour enabled": self.checkBox_contour.isChecked(),
event = {"auto contrast": self.checkBox_auto_contrast.isChecked(),
"contour": self.checkBox_contour.isChecked(),
"index": self.spinBox_event.value(),
"zoom": self.checkBox_zoom_roi.isChecked(),
}
Expand Down Expand Up @@ -137,7 +140,8 @@ def __setstate__(self, state):
for tb in self.signal_widgets:
tb.blockSignals(False)
if "event" in state:
self.checkBox_downsample.setChecked(state["contour enabled"])
self.checkBox_auto_contrast.setChecked(state["auto contrast"])
self.checkBox_contour.setChecked(state["contour"])
self.spinBox_event.setValue(state["event"]["index"])
self.checkBox_zoom_roi.setChecked(state["event"]["zoom"])

Expand Down Expand Up @@ -189,12 +193,14 @@ def show_event(self, event):
# Update selection point in scatter plot
self.widget_scatter.setSelection(self.data_x[event],
self.data_y[event])

imkw = self.imkw.copy()
# update image
state = self.__getstate__()
with dclab.new_dataset(state["plot"]["path"]) as ds:
if "image" in ds:
cellimg = ds["image"][event]
if state["event"]["auto contrast"]:
imkw["levels"] = cellimg.min(), cellimg.max()
# convert to RGB
cellimg = cellimg.reshape(
cellimg.shape[0], cellimg.shape[1], 1)
Expand All @@ -204,11 +210,11 @@ def show_event(self, event):
# might run into trouble displaying random contours.
if "mask" in ds and len(ds["mask"]) > event:
mask = ds["mask"][event]
if state["event"]["contour enabled"]:
if state["event"]["contour"]:
# compute contour image from mask
cont = mask ^ binary_erosion(mask)
# set red contour pixel values in original image
cellimg[cont, 0] = 150
cellimg[cont, 0] = int(imkw["levels"][1]*.7)
cellimg[cont, 1] = 0
cellimg[cont, 2] = 0
if state["event"]["zoom"]:
Expand All @@ -226,7 +232,7 @@ def show_event(self, event):
else:
cellimg = np.zeros((50, 50, 3))

self.imageView_image.setImage(cellimg, **self.imkw)
self.imageView_image.setImage(cellimg, **imkw)

def on_tool(self):
"""Show and hide tools when the user selected a tool button"""
Expand Down
55 changes: 36 additions & 19 deletions shapeout2/gui/quick_view.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>941</width>
<height>494</height>
<width>1096</width>
<height>573</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -275,24 +275,41 @@
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBox_contour">
<property name="text">
<string>Show contour</string>
</property>
<property name="checked">
<bool>true</bool>
<layout class="QGridLayout" name="gridLayout_3">
<property name="topMargin">
<number>0</number>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_zoom_roi">
<property name="text">
<string>Zoom to ROI</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<item row="0" column="0">
<widget class="QCheckBox" name="checkBox_contour">
<property name="text">
<string>Show contour</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkBox_zoom_roi">
<property name="text">
<string>Zoom to ROI</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBox_auto_contrast">
<property name="text">
<string>Auto contrast</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="ImageView" name="imageView_image">
Expand Down

0 comments on commit a01df64

Please sign in to comment.