numpy 从图像中提取沿着线的强度分布

byqmnocz  于 2023-04-30  发布在  其他
关注(0)|答案(1)|浏览(123)

我有一个numpy数组,其中包含一些图像数据(ch4_out)。现在,我想提取沿着特定线(水平)的强度分布。我正在使用skimage模块中的profile_line函数来执行此操作,但我遇到了错误。我正在寻求一些帮助来解决我的代码。
显示的错误为
order = _validate_interpolation_order(image.d类型,顺序)

# reading multiple images 
S01=[i for i in 
glob.glob("C:/Users/experiment/S01/*.tif")]

# Averaging images
ch4=np.array([np.array(Image.open(fname)) for fname in
S01])
ch4_avg=np.array(np.mean(ch4,axis=(0)),dtype=np.uint16)
ch4_out=Image.fromarray(ch4_avg) # image data as numpy array

#plotting figure
plt.figure()
plt.subplot(1,2,1)
plt.imshow(ch4_out,cmap='gray',interpolation='none') 
#code works fine until this point

#Now, extract intensity profile at pixel along horizontal line x (2 to 1000) at a height in vertical direction of 730 
pixels

p = profile_line(ch4_out, (2, 1000), (730, 730)) 
# coordinates for horizontal (2,1000) and vertical 
(730,730))
plt.imshow(p)
plt.show()
n6lpvg4x

n6lpvg4x1#

这是我使用的解决方案,

blob_img = io.imread(r"C:\Users\Oct_epb.tiff")
blob_img_arr = np.array(blob_img)# convert to array
# call the profile line module
start = (250, 0)#in Array co-ordinates
end = (100,blob_img_arr.shape[0]-1)
plt.grid(True)
profile = profile_line(blob_img_arr, start, end, linewidth=2)
# show the position of the line
io.imshow(blob_img, cmap='gray')
plt.plot([start[1],end[1]],[start[0],end[0]],'w--',lw=2)
plt.xlim(0,blob_img_arr.shape[0])
plt.show()
 #Profile line structure
plt.figure(figsize=(4.5,4.5))
plt.plot(profile,"k-")
plt.xlim(0,blob_img_arr.shape[0])

相关问题