Read image coordinates with Python-matplotlib

Introduction

If you do not have mathematical formulas or numerical data and only have a graph image, you may want to read the plot coordinates from the image and quantify it.

I tried using Python's matplotlib to achieve this.

What you are doing

That is. By setting the coordinate axes properly, you should be able to quantify the graph data, but I would like to think about that in the future.

program

$ python3 py_img_test.py
/Users/kk/.pyenv/versions/3.5.2/lib/python3.5/site-packages/matplotlib/backend_bases.py:2437: MatplotlibDeprecationWarning: Using default event loop until function specific to this GUI is implemented
  warnings.warn(str, mplDeprecation)

I got the above warning and couldn't get rid of it, so I put the line below to get rid of the warning.

import warnings;warnings.filterwarnings('ignore')

`` `ginput``` is used to get the click coordinates.

Below is a sentence that adjusts the margins of the image and outputs it, which is often forgotten even though it is often used.

plt.savefig('fig_test.png', bbox_inches="tight", pad_inches=0.2)

Full program

py_img_test.py


from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
import warnings;warnings.filterwarnings('ignore')

im=Image.open('fig_PSHQ1.png')
im_list=np.asarray(im)
plt.imshow(im_list)

nn=5
a=plt.ginput(n=nn)
for x,y in a:
    print(x,y)
    plt.plot( x,y, 'ro' )

plt.savefig('fig_test.png', bbox_inches="tight", pad_inches=0.2)
plt.show()

Image display example

If you load a separately created graph (file name: fig_PSHQ1.png) and click 5 points on the image, the console output below and the graph showing the click points in red circles will be displayed and saved.

Console output

$ python3 py_img_test.py
205.951612903 1005.9516129
318.85483871 825.306451613
489.822580645 689.822580645
680.14516129 589.822580645
1125.30645161 415.629032258

Output image

fig_test.png

Reference site

Display image

http://qiita.com/zaburo/items/5637b424c655b136527a [http://www.mwsoft.jp/programming/computer_vision_with_python/1_2_matplotlib.html] (http://www.mwsoft.jp/programming/computer_vision_with_python/1_2_matplotlib.html)

Get coordinate values

[http://seesaawiki.jp/python-project/d/%BA%C2%C9%B8%C3%CD%BC%E8%C6%C0(ginput)] (http://seesaawiki.jp/python-project/d/%BA%C2%C9%B8%C3%CD%BC%E8%C6%C0(ginput))

Turn off the warning

http://dothiko.hatenablog.com/entry/2014/11/27/001000

Recommended Posts

Read image coordinates with Python-matplotlib
Read the coordinates of the plot on the graph with Python-matplotlib (super beginner)
Read the graph image with OpenCV and get the coordinates of the final point of the graph
Medical image analysis with Python 1 (Read MRI image with SimpleITK)
Image processing with MyHDL
Image recognition with keras
Read digital image processing
Image processing with Python
Read excel with openpyxl
Image Processing with PIL
Read QR code from image file with Python (Mac)
Image processing with Python (Part 2)
Read csv with python pandas
Image processing with PIL (Pillow)
Image editing with python OpenCV
Image upload & customization with django-ckeditor
Sorting image files with Python (2)
Sorting image files with Python (3)
Easy image classification with TensorFlow
Create Image Viewer with Tkinter
Image processing with Python (Part 1)
Tweet with image in Python
Sorting image files with Python
Image processing with Python (Part 3)
Image caption generation with Chainer
Get image features with OpenCV
Image recognition with Keras + OpenCV
[Python] Image processing with scikit-image
Read json data with python
Cut out an image with python
Real-time image processing basics with opencv
[Python] Using OpenCV with Python (Image Filtering)
[Python] Using OpenCV with Python (Image transformation)
Image segmentation with scikit-image and scikit-learn
Image processing with Python 100 knocks # 3 Binarization
[python] Read information with Redmine API
Image classification with wide-angle fundus image dataset
Let's do image scraping with Python
Read files in parallel with Python
Find image similarity with Python + OpenCV
Try blurring the image with opencv2
Convert PDF to image with ImageMagick
Image processing with Python 100 knocks # 2 Grayscale
Compare two images with image hash
Read fbx from python with cinema4d
Read system environment variables with python-Part 1
Send image with python, save with php
Read system environment variables with python-Part 2
Image upload function with Vue.js + Flask
Gradation image generation with Python [1] | np.linspace
[Image recognition] How to read the result of automatic annotation with VoTT