[英]How do I measure the length of the scale bar in pixel point?
How do I measure the length of the scale bar in pixel point, which is only the white area in the picture? 如何测量像素点(仅是图片中的白色区域)中比例尺的长度?
from PIL import Image
im = Image.open("scalebar.png")
width, height = im.size
print(width, height)
638 58 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' object is not subscriptable TypeError:“ AxesImage”对象不可下标
plt.plot(pixels,profile)
plt.xlabel('Pixels')
plt.ylabel('Intensity');
this is what I am trying to do. 这就是我想要做的。
When you use imshow('scalebar.png')
it will return a handle to the figure, and not the data. 使用imshow('scalebar.png')
,它将返回图形的句柄,而不是数据。 You can simply convert the image data directly to a numpy array. 您可以简单地将图像数据直接转换为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.