我有困难切片图像使用坐标作为起点和终点。到目前为止,我有以下代码
hdulist = fits.open(filename)
hdr= hdulist[0].header
import numpy as np
import scipy
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure, show
from astropy.io import fits
from scipy import interpolate
data=hdulist[0].data
#Make a line with "num" points
D, B = input('Enter the coordinates of the starting point:').split(',')
E, C = input("Enter the coordinates of the stopping point: ").split(',')
x0= float(D)
x1= float(E)
y0= float(B)
y1= float(C)
x = np.arange(data.shape[1])
y = np.arange(data.shape[0])
#length = int((np.hypot(x1-x0, y1-y0))) (can be used instead of num_points)
num_points = 1000
xvalues = np.linspace(x0, x1, num_points)
yvalues = np.linspace(y0, y1, num_points)
f = scipy.interpolate.interp2d(x, y, data) #default is linear
# Extract the values along the line
profile = f(xvalues, yvalues) #this gives me a 2D array, I think it needs to be 1D
#c = profile.flatten()
print(profile.shape)
“轮廓”不是线性的而是立方的。有没有一种方法可以使轮廓线性化,这样我就可以在起点和终点之间的点上切割图像?我只想让'个人资料'1D而不是2D
我想把它画成这样:
^{pr2}$我的代码不工作,因为我得到的绘图不是显示一条直线的一段,而是一个立方体的一部分。在
从interp2D的文档中可以看出,网格是由插值构建的。凭直觉,我觉得你需要网格的diagonal。快速修改代码:
这将返回以下结果:
注意:我没有考虑二维图中的坐标(这就是为什么两条线看起来一样大)。在
相关问题 更多 >
编程相关推荐