【问题标题】:skimage profile_line does not make senseskimage profile_line 没有意义
【发布时间】:2020-06-16 19:40:48
【问题描述】:

我正在尝试使用测量配置文件来检测一系列管中的荧光,因此我编写了以下代码

import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage
from skimage.measure import profile_line
import os
import argparse
import string  
from PIL import Image


plt.rcParams['font.size']=16
plt.rcParams['font.family'] = 'sans-serif'


ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="Path to the image")
args = vars(ap.parse_args())
imagen = Image.open(args["image"]) 
imagename=args["image"]  

img = np.array(imagen)

#profile position
start=(0,35)
end=(1300,35)

#profile_line
profile = profile_line(img,start,end, linewidth=5)
fig, ax = plt.subplots(2,1,figsize=(15,9))
ax[0].imshow(imagen, cmap=plt.cm.gist_earth, interpolation='gaussian',origin='lower',alpha=1)
ax[0].plot([start[0],end[0]],[start[1],end[1]],'r-',lw=3)
ax[1].plot(profile)
ax[1].set_title('data points = '+str(profile.shape[0])+'')
plt.tight_layout()
plt.savefig("scipy.jpg")

但我得到了

原图为 有什么建议么 ?它在 x 轴上落在 100...

【问题讨论】:

  • 请分享您使用的图像 - 不是它的情节,而是您在Image.open() 中使用的实际图像。谢谢。
  • 尝试将您的x,y 坐标换成profile_line()...35,035,1300
  • 上帝保佑你或布达,或任何人......非常感谢

标签: python scipy scikit-image


【解决方案1】:

根据@MarkSetchell 告诉我交换 x 和 y 问题已解决

我需要在子图方向上做一些工作,但看起来很不错的解决方案

PS:重做

import matplotlib
matplotlib.use("Agg")
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage
from skimage.measure import profile_line
import os
import argparse
import string  
from PIL import Image


plt.rcParams['font.size']=6
plt.rcParams['font.family'] = 'sans-serif'


ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="Path to the image")
args = vars(ap.parse_args())
imagen = Image.open(args["image"]) 
imagename=args["image"]  

img = np.array(imagen)

start=(35,0)
end=(35,1300)
profile = profile_line(img,start,end, linewidth=2)


fig, ax = plt.subplots(2,1)
major_ticks = np.arange(0,1350,50)
fig.subplots_adjust(hspace=0,wspace=0)



ax[1].imshow(imagen, cmap=plt.cm.gist_earth, interpolation='gaussian',origin='lower',alpha=1)
ax[1].plot([start[1],end[1]],[start[0],end[0]],'r-',lw=2)
ax[1].set_xticks(major_ticks)
ax[1].grid(color="black", linewidth=0.2)
ax[1].grid(True)

ax[0].plot(profile)
ax[0].set_title('data points = '+str(profile.shape[0])+'')
ax[0].set_xticks(major_ticks)
ax[0].grid(color="black", linewidth=0.2)
ax[0].grid(True)

【讨论】:

  • 写得好并与 SO 分享。我认为你的红线需要回到另一个方向......
  • 酷,你也可以接受它是正确的,并抓住积分。
  • 你不能用 ? 投票,但你可以用 ✅ 接受它
猜你喜欢
  • 2017-09-21
  • 1970-01-01
  • 2017-07-16
  • 1970-01-01
  • 1970-01-01
  • 2021-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多