-
Notifications
You must be signed in to change notification settings - Fork 98
Open
Labels
Description
Problem Description
I am trying to add the functionality to set ROI with a mouse using RangeSelection2D.
However, I am getting the following error after right-clicking the image displayed.
File "/Users/sshiozawa/.edm/envs/python-class/lib/python3.6/site-packages/chaco/linear_mapper.py", line 67, in map_data
return (screen_val - self.low_pos) / self._scale + self.range.low
TypeError: unsupported operand type(s) for -: 'list' and 'float'
I see some old attempt here.
Reproduction Steps:
Run the following code with an image file and then right-click the image in the interface.
from skimage import io
import matplotlib.pyplot as plt
from traits.api import Array, Bool, Button, Enum, File, Float, HasTraits, Instance, Int, List, Str, on_trait_change
from traitsui.api import CheckListEditor, Group, Item, HGroup, spring, UItem, View
from chaco.api import Plot, ArrayPlotData
from chaco.tools.api import PanTool, RangeSelection2D, ZoomTool
from enable.api import BaseTool, ComponentEditor
class Image_GUI(HasTraits):
# Define Parameters
file_path = File(exists=True)
img = Array()
plot = Instance(Plot)
# Define File Select Function
def _file_path_changed(self):
self.img = io.imread(self.file_path)
# Define Plot Function
def _plot_default(self):
img = self.img
# Show Plot if Image is loaded
if len(img) > 0:
# Show Plot
data = ArrayPlotData(img=img)
plot = Plot(data)
plot.img_plot('img', origin='top left')
# Set Aspect Ratio
height, width, _ = img.shape
plot.aspect_ratio = width / height
plot.tools.append(RangeSelection2D(plot))
else:
plot = Plot()
return plot
# Run Plot Method if file is changed
@on_trait_change('file_path')
def create_new_plot(self):
self.plot = self._plot_default()
# Configure GUI Settings
traits_view = View(Item('file_path'),
UItem('plot', editor=ComponentEditor()))
if __name__ == '__main__':
img_gui = Image_GUI()
img_gui.configure_traits()Expected behavior:
[Describe expected behavior here]
OS, Python version:
macOS, Python 3.6.12