Commit 36968e79 authored by k-dominik's avatar k-dominik

added gaussian filter

parent 7b58ca3e
Pipeline #10485 passed with stage
in 4 minutes and 23 seconds
......@@ -66,6 +66,52 @@
" - *Here we will do something similar to adaptive background subtraction when we do adaptive thresholding*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Prerequisite: Load an image"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import imageio\n",
"import io\n",
"import numpy as np\n",
"import requests\n",
"import skimage\n",
"\n",
"from matplotlib import pyplot as plt\n",
"from matplotlib import cm"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#load and display an image\n",
"image_file = (\n",
" \"https://git.embl.de/grp-bio-it/image-analysis-training-resources/raw/\"\n",
" \"1fc71747f0caddfd3e206b700b41f2bf69c07a49/image_data/xy_8bit__two_cells.tif\"\n",
")\n",
"\n",
"buffer = io.BytesIO()\n",
"buffer.write(requests.get(image_file).content)\n",
"buffer.seek(0)\n",
"\n",
"image = imageio.imread(buffer, format='tif')\n",
"f = plt.figure()\n",
"s = f.add_subplot(111)\n",
"s.imshow(image, cmap=cm.gray)"
]
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -82,9 +128,38 @@
"\n",
"**How to choose the correct value of $\\sigma$?**\n",
"\n",
"This depends a lot on your images, in particular on the pixel size. In general, the chosen $\\sigma$ should be large enough to blur out noise but small enough so the \"structures of interest\" do not get blurred too much. Usually, the best value for $\\sigma$ is simply found by trying out some different options and looking at the result. \n"
"This depends a lot on your images, in particular on the pixel size. In general, the chosen $\\sigma$ should be large enough to blur out noise but small enough so the \"structures of interest\" do not get blurred too much. Usually, the best value for $\\sigma$ is simply found by trying out some different options and looking at the result.\n",
"\n",
"\n",
"Useful links:\n",
"\n",
"* [scikit-image filters](https://scikit-image.org/docs/dev/api/skimage.filters.html#skimage.filters.gaussian)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sigma = 3\n",
"filtered_image = skimage.filters.gaussian(image, sigma=sigma)\n",
"f = plt.figure()\n",
"s = f.add_subplot(121)\n",
"s.imshow(image, cmap=cm.gray)\n",
"s.set_title(\"original image\")\n",
"s = f.add_subplot(122)\n",
"s.imshow(filtered_image, cmap=cm.gray)\n",
"s.set_title(f\"filtered image with $\\sigma$ = {sigma}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment