在jupyter笔记本中交互式标记图像

问题描述 投票:1回答:1

我有一张图片清单:

pictures = {im1,im2,im3,im4,im5,im6}

哪里

IM1:enter image description here

IM2:enter image description here

IM3:enter image description here

IM4:enter image description here

IM5:enter image description here

IM6:enter image description here

我想将图片分配给标签(1,2,3,4等)

例如,这里图片1至3属于标签1,图片4属于标签2,图片5属于标签3,图片6属于标签4。

- > label = {1,1,1,2,3,4}

因为我需要在标记它们时看到图像,所以我需要一种方法来标记它们。我在考虑创建一个图像数组:

enter image description here

然后我通过单击属于相同标签的第一张和最后一张图片来定义范围,例如:

enter image description here

你怎么看 ?这有点可能吗?

我想为不同的图片范围分配不同的标签。

enter image description here

例如:当一个人完成选择第一个标签后,可以通过双击指示它,然后选择第二个标签范围,然后双击,然后选择第三个标签范围,然后双击,然后选择第四个标签范围等。

它不一定要双击以更改标签的选择,它也可能只是一个buttom或任何其他你可能有的想法。

最后,应该有标签列表。

python-3.x image opencv jupyter-notebook interactive
1个回答
3
投票

从本质上讲,您正在寻找的大多数交互归结为能够显示图像,并实时检测它们的点击。在这种情况下,您可以使用jupyter小部件(aka ipywidgets)模块来实现您所寻找的大部分(如果不是全部)。

看看here描述的按钮小部件,以及如何注册其click事件的说明。问题 - 我们无法在按钮上显示图像,我在ipywidgets文档中找不到任何方法。有一个image小部件,但它不提供on_click事件。因此,构建自定义布局,每个图像下方都有一个按钮:

COLS = 4
ROWS = 2
IMAGES = ...
IMG_WIDTH = 200
IMG_HEIGHT = 200

def on_click(index):
    print('Image %d clicked' % index)

import ipywidgets as widgets
import functools

rows = []

for row in range(ROWS):
    cols = []
    for col in range(COLS):
        index = row * COLS + col
        image = widgets.Image(
            value=IMAGES[index], width=IMG_WIDTH, height=IMG_HEIGHT
        )
        button = widgets.Button(description='Image %d' % index)
        # Bind the click event to the on_click function, with our index as argument
        button.on_click(functools.partial(on_click, index))

        # Create a vertical layout box, image above the button
        box = widgets.VBox([image, button])
        cols.append(box)

    # Create a horizontal layout box, grouping all the columns together
    rows.append(widgets.HBox(cols))

# Create a vertical layout box, grouping all the rows together
result = widgets.VBox(rows)

从技术上讲,您还可以编写自定义小部件来显示图像并聆听点击,但我认为不值得您花时间和精力。

祝好运!

© www.soinside.com 2019 - 2024. All rights reserved.