{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Perform Illumination correction on an Image\n", "The notebook takes an image as a parameter and uses [scikit-image](https://scikit-image.org/) to perform some illumination correction" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Install dependencies if required\n", "The cell below will install dependencies if you choose to run the notebook in [Google Colab](https://colab.research.google.com/notebooks/intro.ipynb#recent=true)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%pip install omero-py" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Import Packages" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython import get_ipython\n", "from omero.gateway import BlitzGateway\n", "import matplotlib.pyplot as plt\n", "from skimage.morphology import disk, white_tophat\n", "from getpass import getpass" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### OMERO Credentials" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "HOST = 'wss://workshop.openmicroscopy.org/omero-ws'\n", "conn = BlitzGateway(input(\"Username: \"),\n", " getpass(\"OMERO Password: \"),\n", " host=HOST, secure=True)\n", "conn.connect()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### OMERO Image ID" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# To be modified\n", "# ex: Select an Image from the dataset named 'PTRE' and enter its Id\n", "image_id = 11270" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Print Image Name" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "image = conn.getObject(\"Image\", image_id)\n", "print(image.getName(), image.getDescription())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Split channel view for an individual plane" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "get_ipython().run_line_magic('matplotlib', 'inline')\n", "pixels = image.getPrimaryPixels()\n", "channels = image.getChannels()\n", "plt.figure(figsize=(25, 20))\n", "size_c = image.getSizeC()\n", "for idx in range(0, size_c):\n", " plt.subplot(1, 5, idx+1)\n", " image_plane = pixels.getPlane(0, idx, 0)\n", " plt.imshow(image_plane, cmap='gray')\n", " plt.axis('off')\n", " plt.title('Channel' + str(idx))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Tophat Filter and display the images" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "get_ipython().run_line_magic('matplotlib', 'inline')\n", "\n", "image_plane = pixels.getPlane(0, 1, 0)\n", "\n", "selem = disk(25)\n", "w_tophat = white_tophat(image_plane, selem)\n", "\n", "plt.figure(figsize=(25, 20))\n", "\n", "plt.subplot(1, 5, 1)\n", "plt.imshow(image_plane, cmap='gray')\n", "plt.axis('off')\n", "plt.title('Raw Image')\n", "\n", "plt.subplot(1, 5, 2)\n", "plt.imshow(w_tophat, cmap='gray')\n", "plt.axis('off')\n", "plt.title('Top-Hat Filtered Image')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Close the connection to the OMERO server" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "conn.close()" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "### License (BSD 2-Clause)\n", "Copyright (C) 2019-2021 University of Dundee. All Rights Reserved.\n", "\n", "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n", "\n", "Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n", "Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n", "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ] } ], "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.8" } }, "nbformat": 4, "nbformat_minor": 2 }