使用python模块plotdigitizer抠取论文图片中的数据实例详解
技术背景
对于各行各业的研究人员来说,经常会面临这样的一个问题:有一篇不错的文章里面有很好的数据,但是这个数据在文章中仅以图片的形式出现。而假如我们希望可以从该图片中提取出数据,这样就可以用我们自己的形式重新来展现这些数据,还可以额外再附上自己优化后的数据。因此从论文图片中提取数据,是一个非常实际的需求。这里以前面写的量子退火的博客为例,博客中有这样的一张图片:
在这篇文章中,我们将介绍如何使用python从图片上把数据抠取出来。
plotdigitizer的安装
这里我们使用pip来安装python第三方库plotdigitizer,该库的主要功能就是可以自动化的从图片中提取出数据,我们可以使用腾讯的pip镜像源来加速我们的安装过程:
[dechin@dechin-manjaroplotdigitizer]$python3-mpipinstall-ihttps://mirrors.cloud.tencent.com/pypi/simpleplotdigitizer Lookinginindexes:https://mirrors.cloud.tencent.com/pypi/simple Collectingplotdigitizer Downloadinghttps://mirrors.cloud.tencent.com/pypi/packages/89/bb/ff753093458c05ce3b52fd17527b6b0622ca096aadcf561c6316320ab793/plotdigitizer-0.1.3-py3-none-any.whl(20kB) Collectingloguru<0.6.0,>=0.5.3 Downloadinghttps://mirrors.cloud.tencent.com/pypi/packages/6d/48/0a7d5847e3de329f1d0134baf707b689700b53bd3066a5a8cfd94b3c9fc8/loguru-0.5.3-py3-none-any.whl(57kB) |████████████████████████████████|57kB521kB/s Collectingopencv-python<5.0.0,>=4.5.1 Downloadinghttps://mirrors.cloud.tencent.com/pypi/packages/2a/9a/ff309b530ac1b029bfdb9af3a95eaff0f5f45f6a2dbe37b3454ae8412f4c/opencv_python-4.5.1.48-cp38-cp38-manylinux2014_x86_64.whl(50.4MB) |████████████████████████████████|50.4MB467kB/s Collectingnumpy<2.0.0,>=1.19.5 Downloadinghttps://mirrors.cloud.tencent.com/pypi/packages/c7/e6/dccac76b7e825915ffb906beeba5a953597b6cfe1fe686b5276e122cb07c/numpy-1.20.1-cp38-cp38-manylinux2010_x86_64.whl(15.4MB) |████████████████████████████████|15.4MB20.4MB/s Collectingmatplotlib<4.0.0,>=3.3.4 Downloadinghttps://mirrors.cloud.tencent.com/pypi/packages/ab/20/60cfe5d611ac86df07b7b1f9b9582f22f7eda5edbe2124ba85bdf3133822/matplotlib-3.3.4-cp38-cp38-manylinux1_x86_64.whl(11.6MB) |████████████████████████████████|11.6MB4.4MB/s Requirementalreadysatisfied:python-dateutil>=2.1in/home/dechin/anaconda3/lib/python3.8/site-packages(frommatplotlib<4.0.0,>=3.3.4->plotdigitizer)(2.8.1) Requirementalreadysatisfied:cycler>=0.10in/home/dechin/anaconda3/lib/python3.8/site-packages(frommatplotlib<4.0.0,>=3.3.4->plotdigitizer)(0.10.0) Requirementalreadysatisfied:pillow>=6.2.0in/home/dechin/anaconda3/lib/python3.8/site-packages(frommatplotlib<4.0.0,>=3.3.4->plotdigitizer)(8.0.1) Requirementalreadysatisfied:kiwisolver>=1.0.1in/home/dechin/anaconda3/lib/python3.8/site-packages(frommatplotlib<4.0.0,>=3.3.4->plotdigitizer)(1.3.0) Requirementalreadysatisfied:pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3in/home/dechin/anaconda3/lib/python3.8/site-packages(frommatplotlib<4.0.0,>=3.3.4->plotdigitizer)(2.4.7) Requirementalreadysatisfied:six>=1.5in/home/dechin/anaconda3/lib/python3.8/site-packages(frompython-dateutil>=2.1->matplotlib<4.0.0,>=3.3.4->plotdigitizer)(1.15.0) Installingcollectedpackages:loguru,numpy,opencv-python,matplotlib,plotdigitizer Attemptinguninstall:numpy Foundexistinginstallation:numpy1.19.2 Uninstallingnumpy-1.19.2: Successfullyuninstallednumpy-1.19.2 Attemptinguninstall:matplotlib Foundexistinginstallation:matplotlib3.3.2 Uninstallingmatplotlib-3.3.2: Successfullyuninstalledmatplotlib-3.3.2 Successfullyinstalledloguru-0.5.3matplotlib-3.3.4numpy-1.20.1opencv-python-4.5.1.48plotdigitizer-0.1.3
通过运行帮助指令,我们可以查看是否安装成功:
[dechin@dechin-manjaroplotdigitizer]$plotdigitizer-h usage:plotdigitizer[-h]--data-pointDATA_POINT[--locationLOCATION][--plotPLOT][--outputOUTPUT] [--preprocess][--debug] INPUT Digitizeimage. positionalarguments: INPUTInputimagefile. optionalarguments: -h,--helpshowthishelpmessageandexit --data-pointDATA_POINT,-pDATA_POINT Datapoints(min3required).Youhavetoclickonthemlater.Atleast3points arerecommended.e.g-p0,0-p10,0-p0,1Makesurethatpointarecomma separatedwithoutanyspace. --locationLOCATION,-lLOCATION Locationofapointsonfigureinpixels(integer).Thesevaluesshouldappearin thesameorderas-poption.Ifnotgiven,youwillbeaskedtoclickonthe figure. --plotPLOTPlotthefinalresult.Requiresmatplotlib. --outputOUTPUT,-oOUTPUT Nameoftheoutputfileelsetrajectorywillbewrittento.traj.csv --preprocessPreprocesstheimage.Usefulwithbadresolutionimages. --debugEnabledebuglogger
执行指令与输出图片
先把需要抠取数据的图片放到当前目录下,然后运行如下指令:
plotdigitizer./test1.png-p0,-1-p20,0-p0,0.1--plotoutput.png
该指令会将test1.png中的数据提取出来,可以使用-o存储为csv格式的数据表格。这里实际使用中我们发现,即使不用plot指令,也会在ManjaroLinux系统下不断的输出打印图片,只有通过kill-9的方式才能强行将进程杀死,有可能是开源库中存在的某个bug。这里展示一下用新的数据绘制出来的效果图:
执行结束后,该图片会被输出到临时文件夹tmp/plotdigitizer/下,但是注意前面产生的图片会被后来的临时文件所覆盖。
总结概要
这里我们仅仅是介绍和演示了plotdigitizer的基本使用方法,这样一个使用python制作的图像数据工具更加符合pythoner的使用习惯和逻辑。虽然实际使用过程中工具可能出现各种各样的问题,但是基本上是一个比较好的工具,值得推荐。
版权声明
本文首发链接为:https://www.cnblogs.com/dechinphy/p/plotdigitizer.html
作者ID:DechinPhy
更多原著文章请参考:https://www.cnblogs.com/dechinphy/
到此这篇关于使用python模块plotdigitizer抠取论文图片中的数据的文章就介绍到这了,更多相关python模块plotdigitizer内容请搜索毛票票以前的文章或继续浏览下面的相关文章希望大家以后多多支持毛票票!
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。