简体   繁体   English

Chaco中的2D范围选择框(有思想)

[英]2D Range Selection Box in Chaco (Enthought)

I am trying to draw a 2D selection box on an image plot and get out the selected region. 我正在尝试在图像绘图上绘制一个2D选择框并找出所选区域。 I cannot find the appropriate tool to do this. 我找不到合适的工具来执行此操作。

I assumed RangeSelection2D would be appropriate for this but it seems to only actually select 1 of the 2 axes. 我认为RangeSelection2D对此适用,但似乎实际上只选择了2个轴中的1个。

I could modify the BetterSelectingZoom where the box mode is similar to what I want. 我可以修改BetterSelectingZoom,其中box模式类似于我想要的模式。 Does anyone know the best way or chaco tool to do this? 有谁知道最好的方法或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()

Unfortunately, there's nothing in Chaco, currently, that does what you need. 不幸的是,Chaco目前没有任何功能可以满足您的需求。 That said, there's an open pull request that adds that functionality: https://github.com/enthought/chaco/pull/162 . 就是说,有一个开放的请求请求添加了该功能: https : //github.com/enthought/chaco/pull/162

As that PR suggests, there's a bit of design discussion about Chaco tools, in general, that needs to happen before more tools are added. 正如该PR所建议的那样,通常需要对Chaco工具进行一些设计讨论,这需要在添加更多工具之前进行。

I hope that helps, 希望对您有所帮助,

-Tony -托尼

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM