Mask an image (np.ndarray) section which lies between two curves
<p>Borrowing this example from astropy:</p>

<pre><code>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()
</code></pre>

<p>I would like to calculate the median pixel value (in y direction for example) which lies between the two curves:</p>

<p><a href="https://i.stack.imgur.com/5QvFz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5QvFz.png" alt="enter image description here"></a></p>

<p>I believe the clever thing would be to create a mask for the region of interest.</p>

<p>Is there a way to generate this mask without looping across the image pixels?</p>

<p>Edit 1: Modified question improve understanding</p>

<p>Edit 2: I changed the example to better represent the question title (curves instead of straight lines)</p>