繁体   English   中英

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

[英]How do I measure the length of the scale bar in pixel point?

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');

这就是我想要做的。

使用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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM