0
我無法使用起始點和停止點的座標切片圖像。到目前爲止,我有以下代碼在兩個aribtray點上切片圖像
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。
我要繪製這樣的:
import numpy as np
from numpy import random
from matplotlib.pyplot import figure, show
vels = np.linspace(0, 530, len(profile))
fig = figure()
frame = fig.add_subplot(1,1,1)
frame.plot(vels, profile)
frame.set_ylabel('y-axis')
frame.set_xlabel('x-axis')
frame.grid(True)
show()
print(vels.shape)
print(profile.shape)
print(len(profile))
我的代碼不工作,因爲我得到的陰謀沒有顯示線路的片,但立方體的一個切片。
非常感謝,我的代碼現在按照我想要的方式工作! – Thomas