在Jupyter Notebook中对图像进行交互式标记 [英] Interactive labeling of images in jupyter notebook
问题描述
我有一张照片清单:
pictures = {im1,im2,im3,im4,im5,im6}
哪里
im1:
im2:
im3:
im4:
im5:
im6:
我想将图片分配给标签(1、2、3、4等)
I want to assign the pictures to labels (1,2,3,4 etc.)
例如,这里的图片1到3属于标签1,图片4属于标签2,图片5属于标签3,图片6属于标签4.
For instance, here pictures 1 to 3 belong to label 1, picture 4 belongs to label 2, picture 5 to label 3, and picture 6 to label 4.
-> label = {1,1,1,2,3,4}
由于在标记图像时需要查看图像,因此需要一种在标记图像时执行此操作的方法.我当时正在考虑创建一系列图像:
Since I need to see the images when I label them, I need a method to do that while labeling them. I was thinking of creating an array of images:
然后我通过单击属于相同标签的第一张和最后一张图片来定义范围,例如:
And then I define the ranges by clicking on the first and last picture belonging to the same labels, so for example:
您如何看待?这可能吗?
我想为不同的图片范围分配不同的标签.
I would like to assign different labels to different ranges of pictures.
例如:完成选择第一个标签后,可以通过双击进行指示,然后选择第二个标签范围,然后双击,然后选择第三个标签范围,然后双击,然后选择第四个标签范围,依此类推.
For instance: When one has finished selecting the first label one could indicate it by a Double-click and then do the selection of the second label range, then Double-click, then do the selection of the third label range, then Double-click, then do the selection of the fourth label range, etc.
不必双击来更改标签的选择,也可以只是一个提示或您可能有的其他任何想法.
It does not have to be Double-clicking to change the selection of the labels, it could also just be a buttom or any other idea that you might have.
最后,应该具有标签列表.
In the end one should have the list of labels.
推荐答案
从本质上讲,您正在寻找的大多数交互都可以归结为能够显示图像并实时检测对它们的点击.在这种情况下,您可以使用jupyter小部件(aka ipywidgets
)模块来实现大部分(如果不是全部)所需的内容.
Essentially, most of the interaction you are looking for boils down to being able to display images, and detect clicks on them in real time. As that is the case, you can use the jupyter widgets (aka ipywidgets
) module to achieve most (if not all) of what you are looking for.
在这里,其中包含有关如何注册其点击事件的说明.问题-我们无法在按钮上显示图像,并且ipywidgets
文档中也没有找到任何方法来执行此操作.有一个图像小部件,但没有提供一个on_click
事件.因此,构建一个自定义布局,并在每个图像下方添加一个按钮:
Take a look at the button widget which is described here with explanation on how to register to its click event. The problem - we can't display an image on a button, and I didn't find any way to do this within the ipywidgets
documentation. There is an image widget, but it does not provide an on_click
event. So construct a custom layout, with a button underneath each image:
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)
从技术上讲,您还可以编写自定义窗口小部件以显示图像并听取点击,但我根本不认为这值得您花费时间和精力.
You can technically also write a custom widget to display an image and listen for a click, but I simply don't believe it's worth your time and effort.
祝你好运!
这篇关于在Jupyter Notebook中对图像进行交互式标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!