From 5208a151e950c07f34b35e181a99ea6573b6dd6c Mon Sep 17 00:00:00 2001 From: ian-coccimiglio Date: Sat, 7 Sep 2024 02:03:12 -0700 Subject: [PATCH 1/2] fix sum images notebook to add two images rather than lists --- test_cases/sum_images.ipynb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test_cases/sum_images.ipynb b/test_cases/sum_images.ipynb index d05b9a6..26f6f5e 100644 --- a/test_cases/sum_images.ipynb +++ b/test_cases/sum_images.ipynb @@ -11,8 +11,7 @@ " \"\"\"\n", " Sums two images pixel-by-pixel and returns the result\n", " \"\"\"\n", - " import numpy as np\n", - " return np.asarray(image1) + np.asarray(image2)" + " return image1 + image2" ] }, { @@ -31,9 +30,9 @@ " \n", " assert np.allclose(candidate(image1, image2), sum_image)\n", "\n", - " image1 = [[1,2,3], [4,5,6]]\n", - " image2 = [[5,6,7], [0,1,2]]\n", - " sum_image = [[6,8,10],[4,6,8]]\n", + " image1 = np.asarray([[1,2,3], [4,5,6]])\n", + " image2 = np.asarray([[5,6,7], [0,1,2]])\n", + " sum_image = np.asarray([[6,8,10],[4,6,8]])\n", " \n", " assert np.allclose(candidate(image1, image2), sum_image)\n" ] @@ -73,7 +72,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.14" + "version": "3.11.7" } }, "nbformat": 4, From 8b81759c0c33f7aa4e9a166540ac931073ecc94f Mon Sep 17 00:00:00 2001 From: ian-coccimiglio Date: Sun, 8 Sep 2024 18:35:43 -0700 Subject: [PATCH 2/2] Fixed functions requesting images providing lists --- test_cases/mask_image.ipynb | 16 +++++++--------- test_cases/mean_squared_error.ipynb | 18 ++++++++---------- test_cases/rgb_to_grey_image_transform.ipynb | 12 ++++++------ test_cases/sum_images.ipynb | 6 +++--- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/test_cases/mask_image.ipynb b/test_cases/mask_image.ipynb index 87c1ed5..3322c6f 100644 --- a/test_cases/mask_image.ipynb +++ b/test_cases/mask_image.ipynb @@ -12,8 +12,6 @@ " Takes a 2D input image and a 2D binary mask image, then applies the mask to the input image and returns the result.\n", " \"\"\"\n", " import numpy as np\n", - " image = np.asarray(image)\n", - " mask = np.asarray(mask)\n", " return image * mask" ] }, @@ -27,27 +25,27 @@ "def check(candidate):\n", " import numpy as np\n", " \n", - " image = [\n", + " image = np.asarray([\n", " [2,2,2,2,2],\n", " [2,2,3,2,2],\n", " [2,3,3,3,2],\n", " [2,2,3,2,2],\n", " [2,2,2,2,2],\n", - " ]\n", - " mask = [\n", + " ])\n", + " mask = np.asarray([\n", " [0,0,0,0,0],\n", " [0,0,1,0,0],\n", " [0,1,1,1,0],\n", " [0,0,1,0,0],\n", " [0,0,0,0,0],\n", - " ]\n", - " reference = [\n", + " ])\n", + " reference = np.asarray([\n", " [0,0,0,0,0],\n", " [0,0,3,0,0],\n", " [0,3,3,3,0],\n", " [0,0,3,0,0],\n", " [0,0,0,0,0],\n", - " ]\n", + " ])\n", " masked_image = candidate(image,mask)\n", " assert np.array_equal(masked_image, reference)" ] @@ -87,7 +85,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.14" + "version": "3.11.7" } }, "nbformat": 4, diff --git a/test_cases/mean_squared_error.ipynb b/test_cases/mean_squared_error.ipynb index cc204ea..7a95d76 100644 --- a/test_cases/mean_squared_error.ipynb +++ b/test_cases/mean_squared_error.ipynb @@ -11,9 +11,6 @@ " \"\"\"\n", " Computes the mean-squared-error of two images compared pixel-by-pixel\n", " \"\"\"\n", - " import numpy as np\n", - " image1 = np.asarray(image1)\n", - " image2 = np.asarray(image2)\n", " return ((image1 - image2)**2).mean()\n", " # adapted from : https://stackoverflow.com/questions/16774849/mean-squared-error-in-numpy" ] @@ -26,32 +23,33 @@ "outputs": [], "source": [ "def check(candidate):\n", - " image1 = [\n", + " import numpy as np\n", + " image1 = np.asarray([\n", " [0,0,0,0,0],\n", " [0,1,0,0,0],\n", " [0,0,0,0,0],\n", " [0,0,0,2,0],\n", " [0,0,0,0,0],\n", - " ]\n", - " image2 = [\n", + " ])\n", + " image2 = np.asarray([\n", " [0,0,0,0,0],\n", " [0,1,0,0,0],\n", " [0,0,0,0,0],\n", " [0,0,0,2,0],\n", " [0,0,0,0,0],\n", - " ]\n", + " ])\n", "\n", " mse = candidate(image1,image2)\n", " print(mse)\n", " assert mse == 0\n", "\n", - " image3 = [\n", + " image3 = np.asarray([\n", " [0,0,0,0,0],\n", " [0,0,0,0,0],\n", " [0,0,0,0,0],\n", " [0,0,0,0,0],\n", " [0,0,0,0,0],\n", - " ]\n", + " ])\n", "\n", " mse = candidate(image1,image3)\n", " print(mse)\n", @@ -103,7 +101,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.14" + "version": "3.11.7" } }, "nbformat": 4, diff --git a/test_cases/rgb_to_grey_image_transform.ipynb b/test_cases/rgb_to_grey_image_transform.ipynb index 7ab861b..0adebee 100644 --- a/test_cases/rgb_to_grey_image_transform.ipynb +++ b/test_cases/rgb_to_grey_image_transform.ipynb @@ -19,9 +19,9 @@ " b = b / rgb_sum\n", " \n", " import numpy as np\n", - " channel_r = np.asarray(rgb_image)[...,0]\n", - " channel_g = np.asarray(rgb_image)[...,1]\n", - " channel_b = np.asarray(rgb_image)[...,2]\n", + " channel_r = rgb_image[...,0]\n", + " channel_g = rgb_image[...,1]\n", + " channel_b = rgb_image[...,2]\n", " grey_image = channel_r * r + \\\n", " channel_g * g + \\\n", " channel_b * b\n", @@ -38,10 +38,10 @@ "source": [ "def check(candidate):\n", " import numpy as np\n", - " assert np.allclose(candidate([[[0,1,2], [3,3,3]]], 0.5, 0.25, 0.25),\n", + " assert np.allclose(candidate(np.asarray([[[0,1,2], [3,3,3]]]), 0.5, 0.25, 0.25),\n", " [[0.75, 3]], atol=0.0001)\n", "\n", - " assert np.allclose(candidate([[[0,1,2], [3,3,3]]], 1, 2, 2),\n", + " assert np.allclose(candidate(np.asarray([[[0,1,2], [3,3,3]]]), 1, 2, 2),\n", " [[1.2, 3]], atol=0.0001)\n", " " ] @@ -89,7 +89,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.14" + "version": "3.11.7" } }, "nbformat": 4, diff --git a/test_cases/sum_images.ipynb b/test_cases/sum_images.ipynb index 26f6f5e..e303642 100644 --- a/test_cases/sum_images.ipynb +++ b/test_cases/sum_images.ipynb @@ -58,9 +58,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:heb]", "language": "python", - "name": "python3" + "name": "conda-env-heb-py" }, "language_info": { "codemirror_mode": { @@ -72,7 +72,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.7" + "version": "3.10.14" } }, "nbformat": 4,