【发布时间】:2017-02-14 13:21:24
【问题描述】:
从astropy借用这个例子:
import numpy as np
from matplotlib import pyplot as plt
from astropy.io import fits
from astropy.wcs import WCS
from astropy.utils.data import download_file
fits_file = 'http://data.astropy.org/tutorials/FITS-images/HorseHead.fits'
image_file = download_file(fits_file, cache=True)
hdu = fits.open(image_file)[0]
wcs = WCS(hdu.header)
fig = plt.figure()
ax = fig.add_subplot(111)
plt.imshow(hdu.data, origin='lower', cmap='cubehelix')
plt.xlabel('X')
plt.ylabel('Y')
x_array = np.arange(0, 1000)
line_1 = 1 * x_array + 20 * np.sin(0.05*x_array)
line_2 = x_array - 100 + 20 * np.sin(0.05*x_array)
plt.plot(x_array, line_1, color='red')
plt.plot(x_array, line_2, color='red')
ax.set_xlim(0, hdu.shape[1])
ax.set_ylim(0, hdu.shape[0])
plt.show()
我想计算位于两条曲线之间的像素中值(例如在 y 方向):
我相信聪明的做法是为感兴趣的区域创建一个蒙版。
有没有办法在不循环图像像素的情况下生成此蒙版?
编辑 1:修改后的问题提高了理解
编辑 2:我更改了示例以更好地表示问题标题(曲线而不是直线)
【问题讨论】:
-
您想计算什么的中值,究竟是什么?如果你想找到那两条线所包围的区域的中心,那不就是找到梯形的中点吗?
-
抱歉,我想说的是 y 方向上这些线之间的像素中值。
-
因此您可以找到该梯形的中点坐标,然后索引图像以找到 RGB 值。现在正在研究解决方案....
-
我不认为我跟着你:输出应该是一个数组而不是一个点......在这种情况下,线也是平行的,但可能不是这样......
-
您在寻找最中间点的 RGB 吗?还是该形状中包含的所有像素的平均 RGB 值?这是两个不同的问题。
标签: python numpy indexing mask scikit-image