简体   繁体   English

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

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

scalebar.png 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 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.

相关问题 给定一个图像,一个像素点和一个以像素为单位的半径。 如何找到它创建的圆形边框的像素坐标 - Given a image, a pixel point and a radious in pixels. How do I find the pixel coordenate of the circle border it creates 如何在 Mayavi2/VTK 中向 plot 添加比例尺? - How do I add a scale bar to a plot in Mayavi2/VTK? 我如何找到给定点的最大长度并使程序在最大长度到达中间的那个点之后停止? - how do i find the greatest length from a given point and make the program stop after that point with the greatest length hits the middle? Maya / Python:如何从各自的特定轴心点缩放多个选定的动画曲线? - Maya/Python: How do I scale multiple selected animation curves each from their own specific pivot point? 如何在matshow中看到比例尺? - How can I see the scale bar in matshow? 如何测量异步事件循环的长度? - How can I measure the length of an asyncio event loop? 如何使大熊猫按类别堆叠的条形图比例达到100% - How do I make pandas catagorical stacked bar chart scale to 100% 如何为每个条形图绘制一条均值虚线并更改轴的比例,python - How can I do a dashed line of mean for each bar plot and change scale of axis, python 如何测量魔杖中弦的界限? - How do I measure the bounds of a string in wand? 如何测量 Python 中经过的时间? - How do I measure elapsed time in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM