龙空技术网

使用python模块plotdigitizer抠取论文图片中的数据

纯技术博主 139

前言:

现在朋友们对“python搜论文”大约比较关切,各位老铁们都需要知道一些“python搜论文”的相关资讯。那么小编在网上网罗了一些有关“python搜论文””的相关内容,希望我们能喜欢,兄弟们一起来学习一下吧!

目录

技术背景plotdigitizer的安装执行指令与输出图片总结概要版权声明技术背景

对于各行各业的研究人员来说,经常会面临这样的一个问题:有一篇不错的文章里面有很好的数据,但是这个数据在文章中仅以图片的形式出现。而假如我们希望可以从该图片中提取出数据,这样就可以用我们自己的形式重新来展现这些数据,还可以额外再附上自己优化后的数据。因此从论文图片中提取数据,是一个非常实际的需求。这里以前面写的量子退火的博客为例,博客中有这样的一张图片:

在这篇文章中,我们将介绍如何使用python从图片上把数据抠取出来。

plotdigitizer的安装

这里我们使用pip来安装python第三方库plotdigitizer,该库的主要功能就是可以自动化的从图片中提取出数据,我们可以使用腾讯的pip镜像源来加速我们的安装过程:

[dechin@dechin-manjaro plotdigitizer]$ python3 -m pip install -i  plotdigitizerLooking in indexes:  plotdigitizer  Downloading  (20 kB)Collecting loguru<0.6.0,>=0.5.3  Downloading  (57 kB)     |████████████████████████████████| 57 kB 521 kB/s Collecting opencv-python<5.0.0,>=4.5.1  Downloading  (50.4 MB)     |████████████████████████████████| 50.4 MB 467 kB/s Collecting numpy<2.0.0,>=1.19.5  Downloading  (15.4 MB)     |████████████████████████████████| 15.4 MB 20.4 MB/s Collecting matplotlib<4.0.0,>=3.3.4  Downloading  (11.6 MB)     |████████████████████████████████| 11.6 MB 4.4 MB/s Requirement already satisfied: python-dateutil>=2.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from matplotlib<4.0.0,>=3.3.4->plotdigitizer) (2.8.1)Requirement already satisfied: cycler>=0.10 in /home/dechin/anaconda3/lib/python3.8/site-packages (from matplotlib<4.0.0,>=3.3.4->plotdigitizer) (0.10.0)Requirement already satisfied: pillow>=6.2.0 in /home/dechin/anaconda3/lib/python3.8/site-packages (from matplotlib<4.0.0,>=3.3.4->plotdigitizer) (8.0.1)Requirement already satisfied: kiwisolver>=1.0.1 in /home/dechin/anaconda3/lib/python3.8/site-packages (from matplotlib<4.0.0,>=3.3.4->plotdigitizer) (1.3.0)Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in /home/dechin/anaconda3/lib/python3.8/site-packages (from matplotlib<4.0.0,>=3.3.4->plotdigitizer) (2.4.7)Requirement already satisfied: six>=1.5 in /home/dechin/anaconda3/lib/python3.8/site-packages (from python-dateutil>=2.1->matplotlib<4.0.0,>=3.3.4->plotdigitizer) (1.15.0)Installing collected packages: loguru, numpy, opencv-python, matplotlib, plotdigitizer  Attempting uninstall: numpy    Found existing installation: numpy 1.19.2    Uninstalling numpy-1.19.2:      Successfully uninstalled numpy-1.19.2  Attempting uninstall: matplotlib    Found existing installation: matplotlib 3.3.2    Uninstalling matplotlib-3.3.2:      Successfully uninstalled matplotlib-3.3.2Successfully installed loguru-0.5.3 matplotlib-3.3.4 numpy-1.20.1 opencv-python-4.5.1.48 plotdigitizer-0.1.3

通过运行帮助指令,我们可以查看是否安装成功:

[dechin@dechin-manjaro plotdigitizer]$ plotdigitizer -husage: plotdigitizer [-h] --data-point DATA_POINT [--location LOCATION] [--plot PLOT] [--output OUTPUT]                     [--preprocess] [--debug]                     INPUTDigitize image.positional arguments:  INPUT                 Input image file.optional arguments:  -h, --help            show this help message and exit  --data-point DATA_POINT, -p DATA_POINT                        Datapoints (min 3 required). You have to click on them later. At least 3 points                        are recommended. e.g -p 0,0 -p 10,0 -p 0,1 Make sure that point are comma                        separated without any space.  --location LOCATION, -l LOCATION                        Location of a points on figure in pixels (integer). These values should appear in                        the same order as -p option. If not given, you will be asked to click on the                        figure.  --plot PLOT           Plot the final result. Requires matplotlib.  --output OUTPUT, -o OUTPUT                        Name of the output file else trajectory will be written to <INPUT>.traj.csv  --preprocess          Preprocess the image. Useful with bad resolution images.  --debug               Enable debug logger
执行指令与输出图片

先把需要抠取数据的图片放到当前目录下,然后运行如下指令:

plotdigitizer ./test1.png -p 0,-1 -p 20,0 -p 0,0.1 --plot output.png

该指令会将test1.png中的数据提取出来,可以使用-o存储为csv格式的数据表格。这里实际使用中我们发现,即使不用plot指令,也会在Manjaro Linux系统下不断地输出打印图片,只有通过kill -9的方式才能强行将进程杀死,有可能是开源库中存在的某个bug。这里展示一下用新的数据绘制出来的效果图:

执行结束后,该图片会被输出到临时文件夹tmp/plotdigitizer/下,但是注意前面产生的图片会被后来的临时文件所覆盖。

总结概要

这里我们仅仅是介绍和演示了plotdigitizer的基本使用方法,这样一个使用python制作的图像数据工具更加符合pythoner的使用习惯和逻辑。虽然实际使用过程中工具可能出现各种各样的问题,但是基本上是一个比较好的工具,值得推荐。

版权声明

本文首发链接为:

作者ID:DechinPhy

更多原著文章请参考:

标签: #python搜论文 #python抓取论文 #python抓取论文代码