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

作者:陆言君的博客 时间:2023-07-14 01:50:52 

技术背景

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

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

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

plotdigitizer的安装

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


[dechin@dechin-manjaro plotdigitizer]$ python3 -m pip install -i https://mirrors.cloud.tencent.com/pypi/simple plotdigitizer
Looking in indexes: https://mirrors.cloud.tencent.com/pypi/simple
Collecting plotdigitizer
Downloading https://mirrors.cloud.tencent.com/pypi/packages/89/bb/ff753093458c05ce3b52fd17527b6b0622ca096aadcf561c6316320ab793/plotdigitizer-0.1.3-py3-none-any.whl (20 kB)
Collecting loguru<0.6.0,>=0.5.3
Downloading https://mirrors.cloud.tencent.com/pypi/packages/6d/48/0a7d5847e3de329f1d0134baf707b689700b53bd3066a5a8cfd94b3c9fc8/loguru-0.5.3-py3-none-any.whl (57 kB)
  |████████████████████████████████| 57 kB 521 kB/s
Collecting opencv-python<5.0.0,>=4.5.1
Downloading https://mirrors.cloud.tencent.com/pypi/packages/2a/9a/ff309b530ac1b029bfdb9af3a95eaff0f5f45f6a2dbe37b3454ae8412f4c/opencv_python-4.5.1.48-cp38-cp38-manylinux2014_x86_64.whl (50.4 MB)
  |████████████████████████████████| 50.4 MB 467 kB/s
Collecting numpy<2.0.0,>=1.19.5
Downloading https://mirrors.cloud.tencent.com/pypi/packages/c7/e6/dccac76b7e825915ffb906beeba5a953597b6cfe1fe686b5276e122cb07c/numpy-1.20.1-cp38-cp38-manylinux2010_x86_64.whl (15.4 MB)
  |████████████████████████████████| 15.4 MB 20.4 MB/s
Collecting matplotlib<4.0.0,>=3.3.4
Downloading https://mirrors.cloud.tencent.com/pypi/packages/ab/20/60cfe5d611ac86df07b7b1f9b9582f22f7eda5edbe2124ba85bdf3133822/matplotlib-3.3.4-cp38-cp38-manylinux1_x86_64.whl (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.2
Successfully 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 -h
usage: plotdigitizer [-h] --data-point DATA_POINT [--location LOCATION] [--plot PLOT] [--output OUTPUT]
          [--preprocess] [--debug]
          INPUT

Digitize 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。这里展示一下用新的数据绘制出来的效果图:

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

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

总结概要

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

版权声明

本文首发链接为:https://www.cnblogs.com/dechinphy/p/plotdigitizer.html
作者ID:DechinPhy
更多原著文章请参考:https://www.cnblogs.com/dechinphy/

来源:https://www.cnblogs.com/dechinphy/p/plotdigitizer.html

标签:python,plotdigitizer,模块
0
投稿

猜你喜欢

  • Pycharm配置autopep8实现流程解析

    2021-08-23 05:34:40
  • python和shell获取文本内容的方法

    2023-06-20 05:42:35
  • 用Python 爬取猫眼电影数据分析《无名之辈》

    2023-07-03 17:23:26
  • pydev使用wxpython找不到路径的解决方法

    2023-02-23 05:01:01
  • 利用Python将list列表写入文件并读取的方法汇总

    2023-12-07 13:40:07
  • Python的垃圾回收机制深入分析

    2021-05-08 19:35:56
  • python调用win32接口进行截图的示例

    2021-07-22 07:19:45
  • python和shell监控linux服务器的详细代码

    2021-11-09 06:23:22
  • Python图像阈值化处理及算法比对实例解析

    2022-08-14 19:32:33
  • Windows 下更改 jupyterlab 默认启动位置的教程详解

    2023-06-11 13:10:12
  • Python使用xpath实现图片爬取

    2023-07-10 16:45:42
  • 一文带你学会Go select语句轻松实现高效并发

    2024-05-22 10:29:50
  • 关于超级链接的一些问题

    2007-12-07 14:00:00
  • 解决linux下使用python打开terminal时报错的问题

    2022-10-06 10:46:25
  • 部署.Net6项目到docker

    2024-06-05 15:43:46
  • mysql时间戳转成常用可读时间格式的两种方法

    2024-01-18 09:38:24
  • Oracle In和exists not in和not exists的比较分析

    2009-08-27 10:07:00
  • GO语言ini配置文件的读取的操作

    2024-04-23 09:38:36
  • pycharm console 打印中文为乱码问题及解决

    2023-06-15 22:30:02
  • 使用Python+Flask开发博客项目并实现内网穿透

    2021-11-03 14:23:37
  • asp之家 网络编程 m.aspxhome.com