目錄
- 技術(shù)背景
- plotdigitizer的安裝
- 執(zhí)行指令與輸出圖片
- 總結(jié)概要
技術(shù)背景
對于各行各業(yè)的研究人員來說,經(jīng)常會面臨這樣的一個(gè)問題:有一篇不錯(cuò)的文章里面有很好的數(shù)據(jù),但是這個(gè)數(shù)據(jù)在文章中僅以圖片的形式出現(xiàn)。而假如我們希望可以從該圖片中提取出數(shù)據(jù),這樣就可以用我們自己的形式重新來展現(xiàn)這些數(shù)據(jù),還可以額外再附上自己優(yōu)化后的數(shù)據(jù)。因此從論文圖片中提取數(shù)據(jù),是一個(gè)非常實(shí)際的需求。這里以前面寫的量子退火的博客為例,博客中有這樣的一張圖片:
在這篇文章中,我們將介紹如何使用python從圖片上把數(shù)據(jù)摳取出來。
plotdigitizer的安裝
這里我們使用pip
來安裝python第三方庫plotdigitizer
,該庫的主要功能就是可以自動化的從圖片中提取出數(shù)據(jù),我們可以使用騰訊的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 loguru0.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-python5.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 numpy2.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 matplotlib4.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 matplotlib4.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 matplotlib4.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 matplotlib4.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 matplotlib4.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 matplotlib4.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->matplotlib4.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
通過運(yùn)行幫助指令,我們可以查看是否安裝成功:
[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
執(zhí)行指令與輸出圖片
先把需要摳取數(shù)據(jù)的圖片放到當(dāng)前目錄下,然后運(yùn)行如下指令:
plotdigitizer ./test1.png -p 0,-1 -p 20,0 -p 0,0.1 --plot output.png
該指令會將test1.png
中的數(shù)據(jù)提取出來,可以使用-o
存儲為csv格式的數(shù)據(jù)表格。這里實(shí)際使用中我們發(fā)現(xiàn),即使不用plot
指令,也會在Manjaro Linux
系統(tǒng)下不斷的輸出打印圖片,只有通過kill -9
的方式才能強(qiáng)行將進(jìn)程殺死,有可能是開源庫中存在的某個(gè)bug。這里展示一下用新的數(shù)據(jù)繪制出來的效果圖:
執(zhí)行結(jié)束后,該圖片會被輸出到臨時(shí)文件夾tmp/plotdigitizer/
下,但是注意前面產(chǎn)生的圖片會被后來的臨時(shí)文件所覆蓋。
總結(jié)概要
這里我們僅僅是介紹和演示了plotdigitizer的基本使用方法,這樣一個(gè)使用python制作的圖像數(shù)據(jù)工具更加符合pythoner
的使用習(xí)慣和邏輯。雖然實(shí)際使用過程中工具可能出現(xiàn)各種各樣的問題,但是基本上是一個(gè)比較好的工具,值得推薦。
版權(quán)聲明
本文首發(fā)鏈接為:https://www.cnblogs.com/dechinphy/p/plotdigitizer.html
作者ID:DechinPhy
更多原著文章請參考:https://www.cnblogs.com/dechinphy/
到此這篇關(guān)于使用python模塊plotdigitizer摳取論文圖片中的數(shù)據(jù)的文章就介紹到這了,更多相關(guān)python模塊plotdigitizer內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:- python encode和decode的妙用
- Python中docx2txt庫的使用說明
- python docx的超鏈接網(wǎng)址和鏈接文本操作
- 使用pycallgraph分析python代碼函數(shù)調(diào)用流程以及框架解析
- python flask框架詳解
- 解決python 出現(xiàn)unknown encoding: idna 的問題