比例尺.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)
类型错误:"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)