MTF 的 Python 脚本

问题描述 投票:0回答:1

我想用python实现MTF(调制传递函数)脚本。对于此脚本,我想传递图像作为参数并获取 MTF 值作为结果。

此 MTF 值将用于量化项目中图像的清晰度。 以下是我用作开发脚本参考的一些链接 - [目前我正在使用此链接来开发脚本]https://github.com/weiliu4/py_mtf/blob/master/mtf.py https://github.com/habi/GlobalDiagnostiX/blob/master/MTF.py

MTF的定义:MTF定义为线扩散函数的FFT。

线扩散函数定义为边缘扩散函数的导数。边缘扩散函数是沿边缘的值,理想情况下是刀口测试目标。

def ESF(path):
    img=cv2.imread(path)
    img=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    #m_out=0.299*img[:,:,0]+0.589*img[:,:,1]+0.114*img[:,:,2]
    #x=m_out[100,:]
    x=img
    mu=np.sum(x)/(x.shape[0])
    tmp=(x[:]-mu)**2
    sigma=np.sqrt(np.sum(tmp)/(x.shape[0]))
    edge_function=(x[:]-mu)/sigma
    #print(edge_function)
    edge_function=edge_function[::3]
    #lsf=edge_function[:-2]-edge_function[2:]
    lsf=np.abs(np.diff(edge_function))
    mtf=abs(np.fft.fft(lsf))
    print(mtf)
    #print(np.max(mtf))
    mtf=mtf[:]/np.max(mtf)
    mtf=mtf[:len(mtf)//2]
    mtf=np.arange(mtf.shape[0]*mtf.shape[1]).reshape(mtf.shape[0],mtf.shape[1])
    ix=np.arange(mtf.shape[0])/(mtf.shape[0])
    mtf_poly=np.polyfit(ix, mtf,6)
    #print(mtf_poly)
    #mtf_poly=np.squeeze(mtf_poly)
    #print(mtf.shape[0])
    #print(mtf.shape[1])
    #poly=np.poly1d(mtf_poly)
    #print(poly)
    plt.figure()
    plt.title("MTF")
    plt.xlabel(r'Frecuency $[cycles/pixel]$') ; plt.ylabel('mtf')
    p= plt.plot(mtf,'-or')
    #ll = plt.plot(poly(ix))
    #plt.legend([p,ll],["MTF values","polynomial fit"])
    plt.grid()
    #plt.show()

目前我在评估线路时遇到错误

poly=np.poly1d(mtf_poly)

对我做错的事情有任何帮助。另外,有人可以告诉我我是否朝着正确的方向寻找 MTF。

蒂亚

python image-processing computer-vision
1个回答
0
投票

我想你可以尝试更改代码:

x = img

成为:

x = img[100,:]

或者您可以更改图像行上的范围内的 100。修好了

© www.soinside.com 2019 - 2024. All rights reserved.