如何给转换矩阵设定阈值以避免剧烈的转换?

问题描述

我想将点坐标与3组参考点和输入点对齐,然后计算通过skimage.transform.SimilarityTransform获得的变换矩阵。

我想要两组相似数据的情况。如果变换变化太大,例如旋转太大,或者比例变化太大,等等。如何给阈值命令行拒绝不必要的对齐操作?

left case should reject,right case is wanted

import itertools
import numpy as np
import matplotlib.pyplot as plt
import astroalign as aa

print('plotting')
rows = 1
cols = 2
#plt.clf()
plt.figure(figsize=(cols*4.5,rows*4.5+0.2))

set_ref =  np.array([[ 690.65203,1943.856756],[1649.468104,1108.205622],[2456.774633,442.78438 ]])
set_in = np.array([[1581.62219,262.704386],[1929.913,1113.938474],[2323.187672,2160.614239]])

transf,(in_list,ref_list) = aa.find_transform(set_in,set_ref)
print(f'transformation matrix: {transf}')
transf_in = transf(set_in)

plt.subplot(rows,cols,1,title=r'transformation should be rejected!')
plt.scatter(set_ref[:,0],set_ref[:,1],s=500,marker='.',c='r',label='Reference')
plt.scatter(set_in[:,set_in[:,c='b',label='Input')
plt.scatter(transf_in[:,transf_in[:,s=100,marker='+',label='Input Aligned')
for i in [0,2]:
  plt.plot((set_in[i,transf_in[i,0]),(set_in[i,1]),ls='--',c='b')
plt.legend()

set_ref =  np.array([[1443.471952,1863.961825],[2175.827914,468.839108]])
set_in = np.array([[2121.554506,487.32244 ],[1597.757895,1128.497734],[1394.761828,1884.938067]])

transf,2,title=r'transformation should keep')
plt.scatter(set_ref[:,c='b')
plt.legend()

plt.tight_layout()
plt.savefig( 'check_matrix.png',format = 'png')
plt.show()

输出矩阵1:这不好,如何通过此矩阵属性终止动作?

transformation matrix: <SimilarityTransform(matrix=
    [[ 3.71639474e-01,-1.07493173e+00,2.14359711e+03],[ 1.07493173e+00,3.71639474e-01,-1.36388878e+03],[ 0.00000000e+00,0.00000000e+00,1.00000000e+00]])>

输出矩阵2:很好,如何自动继续?

transformation matrix: <SimilarityTransform(matrix=
    [[ 1.00022050e+00,-3.85836943e-03,5.56911066e+01],[ 3.85836943e-03,1.00022050e+00,-2.67518605e+01],1.00000000e+00]])>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...