0

我正在尝试在图像图上绘制一个 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()
4

1 回答 1

0

不幸的是,目前 Chaco 没有任何东西可以满足您的需求。也就是说,有一个开放的拉取请求添加了该功能: https ://github.com/enthought/chaco/pull/162 。

正如 PR 所暗示的,一般来说,在添加更多工具之前,需要对 Chaco 工具进行一些设计讨论。

我希望这会有所帮助,

-托尼

于 2015-04-08T04:28:34.800 回答