在python中倾斜回归线

问题描述

我想使用线性回归(python)对图像进行倾斜校正。我有一个包含x,y和z轴的tiff文件。我从x和z轴上取了一条线,并尝试通过线性回归来倾斜该线。我的动机是对整个图像进行倾斜校正。

我的代码如下:

import tifffile 
import matplotlib.pyplot as plt
from scipy import stats 
import numpy as np 
import math
from scipy import ndimage

im = tifffile.imread('test_2.tif',key =0)

fig=plt.figure()
ax= plt.axes()
plt.imshow(im)
plt.xlabel('distance[mm]')
plt.ylabel('position[mm]')
plt.show()
print(im)
print(im.shape)

x = im[0,400:1000]
im1=tifffile.imread('test_2.tif',key =2)
fig=plt.figure()
plt.imshow(im1)
plt.xlabel('distance[mm]')
plt.ylabel('position[mm]')
plt.show()
print(im1)
print(im1.shape)

y = im1[0,400:1000]
slope,intercept,r_value,p_value,std_err = stats.linregress(x,y)
print("The slope is as follows: {0}".format(slope))
print("The intercept is as follows: {0}".format(intercept))
#(y= mx+b) where m is slope and b is the intercept 
y1 = (slope* x)+ intercept
Residual = y - y1
Residual_errors = (y - y1)**2
Total_errors = sum(Residual_errors)
print("The Total errors is as follows: {}".format(Total_errors))
Tilt_angle = math.degrees(math.atan(slope))
print("The Tilt angle is as follows: {0}".format(Tilt_angle))

解决方法

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

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

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