{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Thresholding" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "import numpy as np\n", "import skimage\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "import urllib\n", "#import ipyvolume as ipv\n", "import ipywidgets as ipw\n", "if not os.path.isfile('Samples/confocal2.tif'):\n", " if not os.path.isdir('Samples'):\n", " os.mkdir('Samples')\n", " #url = 'https://cildata.crbs.ucsd.edu/media/images/10494/10494.tif'\n", " url = 'https://cildata.crbs.ucsd.edu/media/images/41694/41694.tif'\n", " urllib.request.urlretrieve(url, 'Samples/confocal2.tif');\n", "\n", "image = skimage.io.imread('Samples/confocal2.tif')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def thresholding(level, image):\n", " fig = plt.figure(figsize=(10,10))\n", " ax1 = plt.subplot(1,2,1)\n", " plt.imshow(image[:,:,2], cmap = 'gray')\n", " ax1 = plt.subplot(1,2,2)\n", " plt.imshow((image[:,:,2]>level).astype(int), cmap = 'gray',vmin = 0, vmax = 1)\n", " plt.show()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d8fbb7b05d8b47e680ca7b3e1e7def10", "version_major": 2, "version_minor": 0 }, "text/plain": [ "interactive(children=(IntSlider(value=0, description='level', max=255), Output()), _dom_classes=('widget-inter…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "ipw.interactive(thresholding, level = ipw.IntSlider(min =0, max = 255), \n", " image = ipw.fixed(image))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 4 }