如何将线绘制到numpy数组中? [英] How can I draw lines into numpy arrays?

查看:103
本文介绍了如何将线绘制到numpy数组中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够将线绘制到numpy数组中,以获得用于在线手写识别的离线功能.这意味着我根本不需要图像,但是我需要在numpy数组中的某些位置上看起来像给定大小的图像.

I would like to be able to draw lines into numpy arrays to get off-line features for on-line handwriting recognition. This means I don't need the image at all, but I need for some positions in a numpy array who an image of a given size would look like.

我希望能够指定图像大小,然后像这样绘制笔触:

I would like to be able to specify an image size and then draw strokes like this:

import module
im = module.new_image(width=800, height=200)
im.add_stroke(from={'x': 123, 'y': 2}, to={'x': 42, 'y': 3})
im.add_stroke(from={'x': 4, 'y': 3}, to={'x': 2, 'y': 1})
features = im.get(x_min=12, x_max=15, y_min=0, y_max=111)

像这样简单的事情(最好直接用numpy/scipy直接实现)吗?

Is something simple like that possible (preferably directly with numpy / scipy)?

(请注意,我需要灰度插值.因此features应该是[0,255]中的值的矩阵.)

(Please note that I want grey-scale interpolation. So features should be a matrix of values in [0, 255].)

推荐答案

感谢Joe Kington的回答!我正在寻找 skimage.draw.line_aa

Thanks to Joe Kington for the answer! I was looking for skimage.draw.line_aa.

import scipy.misc
import numpy as np
from skimage.draw import line_aa
img = np.zeros((10, 10), dtype=np.uint8)
rr, cc, val = line_aa(1, 1, 8, 4)
img[rr, cc] = val * 255
scipy.misc.imsave("out.png", img)

这篇关于如何将线绘制到numpy数组中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆