我正试图在图像绘图上绘制一个2D选择框,并取出选中的区域。我找不到合适的工具来做这件事。
我假设RangeSelection2D将适合于此,但它似乎实际上只选择了2个轴中的1个。
我可以修改BetterSelectingZoom,其中的框模式类似于我想要的。有没有人知道做这件事的最好的方法或者是chaco工具?
import enthought.traits.api as traits
import enthought.chaco.api as chaco
import enthought.chaco.tools.api as ctools
import enthought.traits.ui.api as ui
from enthought.enable.component_editor import ComponentEditor
class ImageViewer(traits.HasTraits):
plot = traits.Instance(chaco.Plot)
view = ui.View(
ui.Item('plot', editor=ComponentEditor(), show_label=False),
width=600, height=600, resizable=True)
def __init__(self, image_array, *args, **kwargs):
super(ImageViewer, self).__init__(*args, **kwargs)
pd = chaco.ArrayPlotData(imagedata=image_array)
self.plot = chaco.Plot(pd, default_origin='top left')
img_plot = self.plot.img_plot("imagedata")[0]
range_select = ctools.RangeSelection2D(component=img_plot)
range_select.left_button_selects = True
img_plot.tools.append(range_select)
range_overlay = ctools.RangeSelectionOverlay(component=img_plot)
img_plot.overlays.append(range_overlay)
if __name__ == "__main__":
import numpy as np
image = np.random.random_integers(0, 255, size=(20, 20))
imageui = ImageViewer(image)
imageui.configure_traits()发布于 2015-04-08 12:28:35
不幸的是,目前在查科中没有任何东西可以满足您的需求。也就是说,有一个开放的拉取请求添加了该功能:https://github.com/enthought/chaco/pull/162。
正如PR所建议的那样,一般来说,在添加更多工具之前,需要进行一些关于Chaco工具的设计讨论。
我希望这能帮上忙
-Tony
https://stackoverflow.com/questions/29455932
复制相似问题