python - 图像轮廓强度

标签 python image line

为什么我正在处理的图像的强度分布不包括右端?我应该看到 7 个“峰值”,但我没有看到。

下面是我的代码:

from matplotlib import pyplot as plt
from skimage.measure import profile_line
from skimage.io import imread

start = (0, 714) #Start of the profile line
end = (100, 100) #End of the profile line

#image = imread('....tif') #Read the images
profile = profile_line(image, start, end, linewidth=1, mode='constant') #Take the profile line
fig, ax = plt.subplots(2, 1, figsize=(10, 10)) #Create the figures
ax[0].imshow(image) #Show the film at the top
ax[0].plot(start, end, 'r-', lw=2) #Plot a red line across the film
ax[1].plot(profile)
ax[1].grid()

结果图:

enter image description here

我正在处理的胶片:

Film

最佳答案

您在这里混淆了一堆不同的概念。一方面,你的想象是错误的。 skimage.measure.profile_line接受 (row, col) 坐标中的两个点。 matplotlib.pyplot.plot接受两个数据集:xy。通过将 start 绘制为 x 并将 end 绘制为 y,您会迷惑自己,相信您所拥有的线是水平的。让我们采用 profile_line 所切割的 x 坐标(列)并正确绘制它们,y 坐标(行)也是如此:

start = (0, 714) #Start of the profile line
end = (100, 100) #End of the profile line
image = skimage.io.imread(...)

fig, ax = plt.subplots(1, 2)
ax[0].set_title('Wrong')
ax[0].imshow(image)
ax[0].plot(start, end, 'r')
ax[1].set_title('Correct')
ax[1].imshow(image)
ax[1].plot([start[1], end[1]], [start[0], end[0]], 'r')

结果如下:

enter image description here

希望您看到标记为“正确”的图像准确地显示了您在绘图中所看到的内容。

您可以轻松纠正此问题。首先,让我们以复杂的方式进行操作:使用 profile_line。您希望开始和结束 y 坐标相同,并且开始和结束 x 坐标跨越图像。请记住,profile_line 两端都包含在内:

image = skimage.io.imread(...)

start = (100, 0) #Start of the profile line row=100, col=0
end = (100, image.shape[1] - 1) #End of the profile line row=100, col=last

profile = skimage.measure.profile_line(image, start, end)

fig, ax = plt.subplots(1, 2)
ax[0].set_title('Image')
ax[0].imshow(image)
ax[0].plot([start[1], end[1]], [start[0], end[0]], 'r')
ax[1].set_title('Profile')
ax[1].plot(profile)

enter image description here

这看起来好多了。对于垂直和水平横截面,您可以使用简单的 indexing 获得相同的结果。 。图片由 skimage.io.imread 加载是numpy arrays ,所以你可以这样做:

profile = image[100, :]

对于垂直线,例如在第 202 列,您可以沿第二个(列)轴建立索引:

profile = image[:, 202]

关于python - 图像轮廓强度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70246383/

相关文章:

javascript - 如何在 HTML5 Canvas 中正确创建带边框的线

python - 从 python 调用命令行以使用 args 以批处理模式执行程序

python - import modulename 的使用与导入模块的命名空间有什么关系?

python - 一段时间后隐藏在 jupyterlab 中的 svg 图形

html - 使用 CSS 定位图像(对抗默认框/空白)

c# - 如何在没有硬代码字符串的情况下打印函数名称?

python - 使类常量的类型是它所在的类

java - 如何选择目录中的上一张或下一张图像?

android - 使用 Retaining Data Source Supplier 播放动画图像

Eclipse:编辑长行编辑器窗口后自动滚动到行首