{ "cells": [ { "cell_type": "markdown", "id": "8c3882b9", "metadata": {}, "source": [ "# Solutions of exercises\n", "\n", "Exercises are available in a few notebooks. Below are solutions to the exercises.\n", "How to use the notebook:\n", "\n", "* **DO NOT RUN THE NOTEBOOK**\n", "* **Copy the code snippet(s) and run the snippet(s) in the relevant notebook**\n" ] }, { "cell_type": "markdown", "id": "38dce9f9", "metadata": {}, "source": [ "## Exercises from notebook idr0062_prediction" ] }, { "cell_type": "markdown", "id": "75db4ae2", "metadata": {}, "source": [ "### Exercise 1 " ] }, { "cell_type": "code", "execution_count": null, "id": "47d19053", "metadata": {}, "outputs": [], "source": [ "# Question 1: Read the geojson file:\n", "import json\n", "with open(geojson_file) as f:\n", " d = json.load(f)\n", " values = d['features']" ] }, { "cell_type": "code", "execution_count": null, "id": "e8fa7860", "metadata": {}, "outputs": [], "source": [ "# Question 2: Overlay the shapes from a specific plane on the image\n", "z = int(image.getPrimaryPixels().getSizeZ() / 2)\n", "ax = plt.subplot()\n", "plt.imshow(data[0, 0, z, :, :], cmap='gray')\n", "for v in values:\n", " if v[\"properties\"][\"z\"] == z:\n", " label_geojson = numpy.array(v[\"geometry\"][\"coordinates\"])\n", " p = label_geojson.squeeze()\n", " ax.plot(p[:, 0], p[:, 1], linewidth=v[\"properties\"][\"stroke-width\"], color=\"red\")\n", "plt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "omero-guide-python", "language": "python", "name": "omero-guide-python" }, "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.9.18" } }, "nbformat": 4, "nbformat_minor": 5 }