imgSignal.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:imgProcessor 作者: radjkarl 项目源码 文件源码
def scaleParamsFromReference(img, reference):
    # saving startup time:
    from scipy.optimize import curve_fit

    def ff(arr):
        arr = imread(arr, 'gray')
        if arr.size > 300000:
            arr = arr[::10, ::10]
        m = np.nanmean(arr)
        s = np.nanstd(arr)
        r = m - 3 * s, m + 3 * s
        b = (r[1] - r[0]) / 5
        return arr, r, b

    img, imgr, imgb = ff(img)
    reference, refr, refb = ff(reference)

    nbins = np.clip(15, max(imgb, refb), 50)

    refh = np.histogram(reference, bins=nbins, range=refr)[
        0].astype(np.float32)
    imgh = np.histogram(img, bins=nbins, range=imgr)[0].astype(np.float32)

    import pylab as plt
    plt.figure(1)
    plt.plot(refh)

    plt.figure(2)
    plt.plot(imgh)
    plt.show()

    def fn(x, offs, div):
        return (x - offs) / div

    params, fitCovariances = curve_fit(fn, refh, imgh, p0=(0, 1))
    perr = np.sqrt(np.diag(fitCovariances))
    print('error scaling to reference image: %s' % perr[0])
    # if perr[0] < 0.1:
    return params[0], params[1]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号