-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #336 from hhslepicka/image_callback
ENH: Add method to Image View so users can easily hook-up data processing code of their own.
- Loading branch information
Showing
5 changed files
with
172 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,47 @@ | ||
from pydm.PyQt.QtCore import QObject, pyqtSlot, pyqtSignal | ||
from pydm.widgets.channel import PyDMChannel | ||
from pydm import Display | ||
import numpy as np | ||
import threading | ||
from os import path | ||
from skimage.feature import blob_doh | ||
from marker import ImageMarker | ||
from pyqtgraph import mkPen | ||
|
||
|
||
class ImageViewer(Display): | ||
|
||
def __init__(self, parent=None, args=None): | ||
super(ImageViewer, self).__init__(parent=parent, args=args) | ||
self.image_channel = "ca://MTEST:TwoSpotImage" | ||
self.image_width_channel = "ca://MTEST:ImageWidth" | ||
self.ui.imageView.widthChannel = self.image_width_channel | ||
self.ui.imageView.image_channel = "" | ||
self.markers = [] | ||
self.markers_lock = threading.Lock() | ||
self.ui.imageView.process_image = self.process_image | ||
self.ui.imageView.newImageSignal.connect(self.draw_markers) | ||
self.markers = list() | ||
self.blobs = list() | ||
|
||
def ui_filename(self): | ||
return 'image_view.ui' | ||
|
||
def ui_filepath(self): | ||
return path.join(path.dirname(path.realpath(__file__)), self.ui_filename()) | ||
|
||
@pyqtSlot(np.ndarray) | ||
def new_image_received(self, new_waveform): | ||
#Reshape the 1D waveform into 2D | ||
img = new_waveform.reshape((int(512),-1), order='C') | ||
#Find blobs in the image with scikit-image | ||
blobs= blob_doh(img, max_sigma=512, min_sigma=64, threshold=.02) | ||
#Remove any existing blob markers | ||
for m in self.markers: | ||
self.ui.imageView.getView().removeItem(m) | ||
self.markers = [] | ||
#For each blob, add a blob marker to the image | ||
for blob in blobs: | ||
x, y, size = blob | ||
m = ImageMarker((y,x), size=size, pen=mkPen((100,100,255), width=3)) | ||
self.ui.imageView.getView().addItem(m) | ||
self.markers.append(m) | ||
#Show number of blobs in text label | ||
self.ui.numBlobsLabel.setText(str(len(blobs))) | ||
#Send the original image data to the image widget | ||
self.ui.imageView.image_value_changed(new_waveform) | ||
|
||
def channels(self): | ||
return [PyDMChannel(address=self.image_channel, value_slot=self.new_image_received)] | ||
|
||
def draw_markers(self, *args, **kwargs): | ||
with self.markers_lock: | ||
for m in self.markers: | ||
if m in self.ui.imageView.getView().addedItems: | ||
self.ui.imageView.getView().removeItem(m) | ||
|
||
for blob in self.blobs: | ||
x, y, size = blob | ||
m = ImageMarker((y, x), size=size, pen=mkPen((100, 100, 255), width=3)) | ||
self.markers.append(m) | ||
self.ui.imageView.getView().addItem(m) | ||
|
||
self.ui.numBlobsLabel.setText(str(len(self.blobs))) | ||
|
||
def process_image(self, new_image): | ||
# Find blobs in the image with scikit-image | ||
self.blobs = blob_doh(new_image, max_sigma=512, min_sigma=64, threshold=.02) | ||
|
||
# Send the original image data to the image widget | ||
return new_image | ||
|
||
|
||
intelclass = ImageViewer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters