From 565c63049995e43b2d040f60d7002a8eefe9e200 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sun, 7 Apr 2024 18:37:35 +0100 Subject: [PATCH] Use rgb2gray to make image grayscale --- posts/2024/2024-04-03-eclipse.ipynb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/posts/2024/2024-04-03-eclipse.ipynb b/posts/2024/2024-04-03-eclipse.ipynb index e2a44408..912d2a93 100644 --- a/posts/2024/2024-04-03-eclipse.ipynb +++ b/posts/2024/2024-04-03-eclipse.ipynb @@ -42,7 +42,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "b77eac75-539b-42db-91d7-302978bf764c", "metadata": {}, "outputs": [], @@ -56,6 +56,7 @@ "from astropy.coordinates import EarthLocation, SkyCoord\n", "from matplotlib.patches import Circle\n", "from photutils.detection import DAOStarFinder\n", + "from skimage.color import rgb2gray\n", "from skimage.transform import hough_circle, hough_circle_peaks\n", "\n", "import sunpy.coordinates.sun\n", @@ -79,7 +80,7 @@ "\n", "The first step is to read in our image.\n", "As mentioned above, we will be using an image taken during the 2017 eclipse taken with a consumer-grade camera.\n", - "When reading in our image data, we'll invert the y-axis and average over the \"color\" dimension." + "When reading in our image data, we'll invert the y-axis and convert it to a grayscale image." ] }, { @@ -90,7 +91,7 @@ "outputs": [], "source": [ "im_rgb = np.flipud(matplotlib.image.imread(SOLAR_ECLIPSE_IMAGE))\n", - "im = np.average(im_rgb, axis=2)" + "im = rgb2gray(im_rgb)" ] }, { @@ -504,7 +505,7 @@ "fig = plt.figure(figsize=(9,9))\n", "ax = plt.subplot(projection=eclipse_map)\n", "eclipse_map.plot(axes=ax, vmax=20)\n", - "ax.plot_coord(regulus, 'o', markeredgewidth=0.5, markeredgecolor='w', \n", + "ax.plot_coord(regulus, 'o', markeredgewidth=0.5, markeredgecolor='w',\n", " markerfacecolor='None', markersize=10, label='Regulus')\n", "eclipse_map.draw_grid(axes=ax)\n", "eclipse_map.draw_limb(axes=ax)\n", @@ -575,8 +576,8 @@ "metadata": {}, "outputs": [], "source": [ - "daofind = DAOStarFinder(fwhm=3.0, threshold=masked.max()/2) \n", - "sources = daofind(masked) \n", + "daofind = DAOStarFinder(fwhm=3.0, threshold=masked.max()/2)\n", + "sources = daofind(masked)\n", "print(sources)" ] }, @@ -685,7 +686,7 @@ "fig = plt.figure(figsize=(9,9))\n", "ax = plt.subplot(projection=eclipse_map)\n", "eclipse_map.plot(axes=ax, vmax=20)\n", - "ax.plot_coord(regulus, 'o', markeredgewidth=0.5, markeredgecolor='w', \n", + "ax.plot_coord(regulus, 'o', markeredgewidth=0.5, markeredgecolor='w',\n", " markerfacecolor='None', markersize=10, label='Regulus')\n", "eclipse_map.draw_grid(axes=ax)\n", "eclipse_map.draw_limb(axes=ax)\n", @@ -799,7 +800,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.12.2" } }, "nbformat": 4,