Skip to content

Commit

Permalink
Merge pull request #121 from ian-coccimiglio/fix_sum_images
Browse files Browse the repository at this point in the history
Fixing test-cases related to Numpy I/O
  • Loading branch information
haesleinhuepf authored Nov 21, 2024
2 parents 861114b + 8b81759 commit 875a81d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 32 deletions.
16 changes: 7 additions & 9 deletions test_cases/mask_image.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
" applies the mask to the input image and returns the result as numpy array.\n",
" \"\"\"\n",
" import numpy as np\n",
" image = np.asarray(image)\n",
" mask = np.asarray(mask)\n",
" return image * mask"
]
},
Expand All @@ -28,27 +26,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)"
]
Expand Down Expand Up @@ -88,7 +86,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
18 changes: 8 additions & 10 deletions test_cases/mean_squared_error.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
" \"\"\"\n",
" Takes two images provided as numpy arrays and returns the mean-squared-error of the 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"
]
Expand All @@ -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",
Expand Down Expand Up @@ -103,7 +101,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
12 changes: 6 additions & 6 deletions test_cases/rgb_to_grey_image_transform.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,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",
Expand All @@ -39,10 +39,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",
" "
]
Expand Down Expand Up @@ -90,7 +90,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
13 changes: 6 additions & 7 deletions test_cases/sum_images.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
" Sums two images pixel-by-pixel and returns the result.\n",
" All input images and also the result image are of type numpy array.\n",
" \"\"\"\n",
" import numpy as np\n",
" return np.asarray(image1) + np.asarray(image2)"
" return image1 + image2"
]
},
{
Expand All @@ -32,9 +31,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"
]
Expand All @@ -60,9 +59,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": {
Expand Down

0 comments on commit 875a81d

Please sign in to comment.