{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Solutions\n", "This notebook cannot be run on its own. It just serves as a helpful information container for another notebook. Copy the content of the cells below into GenesToPhenotypes.ipynb. **DO NOT RUN THE CELLS**." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 1\n", "The user loops through the images in the dataframe and thresholds each of the images.\n", "Each image is then saved as a TIFF file.\n", "We only use the ``df_filtered`` Data frame." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for index, row in df_filtered.iterrows():\n", " image_id = row['Image']\n", " image = conn.getObject(\"Image\", image_id)\n", " pixels = image.getPrimaryPixels()\n", " image_plane = pixels.getPlane(0, 0, 0)\n", " filtered = scipy.ndimage.median_filter(image_plane, size=3)\n", " threshold = filters.threshold_otsu(filtered)\n", " print('Threshold value is {}'.format(threshold))\n", " predicted = numpy.uint8(filtered > threshold) * 255\n", " name=\"%s/%s.tif\" % (home, image_id)\n", " tifffile.imsave(name, predicted)" ] } ], "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": 4 }