简体   繁体   中英

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

scalebar.png

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

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

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. You can simply convert the image data directly to a numpy array.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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