如何在像素点测量比例尺的长度?

时间:2016-11-13 08:47:20

标签: python

scalebar.png

如何测量像素点中比例尺的长度,这只是图片中的白色区域?

from PIL import Image
im = Image.open("scalebar.png")
width, height = im.size
print(width, height)

638 58

scalebar=io.imshow('scalebar.png')

profile=np.mean(scalebar[31:34,:],axis=0)
pixels=np.arange(1,np.size(profile)+1,1)

TypeError:'AxesImage'对象不可订阅

plt.plot(pixels,profile)
plt.xlabel('Pixels')
plt.ylabel('Intensity');

这就是我想要做的。

1 个答案:

答案 0 :(得分:0)

使用imshow('scalebar.png')时,它将返回图形的句柄,而不是数据。您只需将图像数据直接转换为numpy数组即可。

from PIL import Image
import numpy as np

im = Image.open("scalebar.png")
width, height = im.size
print(width, height)

scalebar = np.asarray(im)
profile = np.mean(scalebar[31:34,:],axis=0)
pixels = np.arange(1,np.size(profile)+1,1)
plot(pixels, profile)