Last time, I introduced a program up to "reading the coordinates of an image", but this time, based on that program, I will read the numerical values on the graph (convert the coordinates of the image to the numerical values on the graph). I tried it.
The input accuracy of the coordinate axes is low, and it is only an approximate value, so it is not a substitute that can be used in practice, but it seems that it has become a substitute that you can imagine "I want to do this kind of thing".
As mentioned above, I think the challenges are to improve the input accuracy of the coordinate axes of the graph and to improve the accuracy when clicking points. From here onward it seems to be quite difficult.
py_img_test1.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)
#click left-top and right-bottom
nn=2
a=plt.ginput(n=nn)
xi=a[0][0]
yi=a[0][1]
xf=a[1][0]
yf=a[1][1]
del a
#click on the graph
nn=5
a=plt.ginput(n=nn)
b=np.array(a)
vec_x=b[:,0]
vec_y=b[:,1]
plt.plot( vec_x,vec_y, 'ro' )
# range of the graph
#(xmin,xmax)=(0,12000)
#(ymin,ymax)=(60,90)
xmin,xmax=map(float,input('xmin xmax= ').split())
ymin,ymax=map(float,input('ymin ymax= ').split())
# calculation of the values
xx=xmin+(xmax-xmin)*(vec_x-xi)/(xf-xi)
yy=ymin-(ymax-ymin)*(vec_y-yf)/(yf-yi)
for x,y in zip(xx,yy):
print(x,y)
plt.savefig('fig_test.png', bbox_inches="tight", pad_inches=0.2)
plt.show()
$ python3 py_img_test1.py
xmin xmax= 0 12000
ymin ymax= 60 90
-31.25 62.1212121212
1937.5 70.202020202
3968.75 74.0404040404
6000.0 77.1717171717
9968.75 82.2222222222
that's all
Recommended Posts