|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "9629f8e8-86e7-4a6d-85a6-a6b34d548545", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# Time some basic operations in movie with varying sizes\n", |
| 9 | + "\n", |
| 10 | + "Notebook to automatically do time some steps of EpiCure:\n", |
| 11 | + "* **Load the movie and segmentation**\n", |
| 12 | + "* **removing the border cells** \n", |
| 13 | + "* **performs the tracking** (with the default parameters)\n", |
| 14 | + "* **perform some basic editions, repeated several times** \n", |
| 15 | + "\n", |
| 16 | + "*This notebook is part of EpiCure release, see https://github.pasteur.fr/Image-Analysis-Hub/epicure for more informations*" |
| 17 | + ] |
| 18 | + }, |
| 19 | + { |
| 20 | + "cell_type": "code", |
| 21 | + "execution_count": null, |
| 22 | + "id": "47dd0f63-87ef-4dce-8034-413b45e77992", |
| 23 | + "metadata": {}, |
| 24 | + "outputs": [], |
| 25 | + "source": [ |
| 26 | + "#### Parent directory to process. It will go through all the sub-folders\n", |
| 27 | + "main_path = \"../../../data/timing/\"\n", |
| 28 | + "imgname = main_path+\"Ecad\"\n", |
| 29 | + "skelname = main_path+\"Ecad_skeleton\"\n", |
| 30 | + "#subnames = [\"-subcrop\", \"-crop-crop\", \"-crop\", \"\", \"-subset\", \"-subset-subset\"]\n", |
| 31 | + "subnames = [\"\", \"-subset\", \"-subset-subset\"]" |
| 32 | + ] |
| 33 | + }, |
| 34 | + { |
| 35 | + "cell_type": "code", |
| 36 | + "execution_count": null, |
| 37 | + "id": "48bf6960-5798-45e9-8271-de1ece6897a4", |
| 38 | + "metadata": {}, |
| 39 | + "outputs": [], |
| 40 | + "source": [ |
| 41 | + "import epicure.epicuring as epicure\n", |
| 42 | + "import epicure.Utils as ut\n", |
| 43 | + "import os\n", |
| 44 | + "import time\n", |
| 45 | + "from vispy import keys\n", |
| 46 | + "import sys\n", |
| 47 | + "\n", |
| 48 | + "original_stdout = sys.stdout\n", |
| 49 | + "\n", |
| 50 | + "def doOneMovie( imgname, skelname, subname ):\n", |
| 51 | + " \"\"\" Process one movie: clear (or not) the border cells and performs tracking \"\"\"\n", |
| 52 | + " print( \"EpiCuring movie \"+imgname+subname+\".tif\" )\n", |
| 53 | + " \n", |
| 54 | + " start_time = time.time()\n", |
| 55 | + " sys.stdout = open( os.devnull, 'w' )\n", |
| 56 | + " epic = epicure.EpiCure()\n", |
| 57 | + " epic.verbose = 0 ## Choose the level of printing infos during process (0: minimal to 3: debug informations)\n", |
| 58 | + " ## Loading movie\n", |
| 59 | + " epic.load_movie( imgname+subname+\".tif\" )\n", |
| 60 | + " sys.stdout = original_stdout\n", |
| 61 | + " ctime = time.time()\n", |
| 62 | + " print( f\"Time to load movie: {ctime-start_time}\" )\n", |
| 63 | + " ## Loading segmentation and initialize all\n", |
| 64 | + " start_time = ctime\n", |
| 65 | + " sys.stdout = open( os.devnull, 'w' )\n", |
| 66 | + " epic.go_epicure( \"epics\", skelname+subname+\".tif\" ) ## start EpiCure, load the segmentation, prepare everything\n", |
| 67 | + " sys.stdout = original_stdout\n", |
| 68 | + " ctime = time.time()\n", |
| 69 | + " print( f\"Time to load segmentation and initialize: {ctime-start_time}\" )\n", |
| 70 | + " print( f\"Nb of untracked cells: {epic.nlabels()}\" )\n", |
| 71 | + " ## Remove border cells\n", |
| 72 | + " start_time = ctime \n", |
| 73 | + " sys.stdout = open( os.devnull, 'w' )\n", |
| 74 | + " epic.editing.border_size.setText(\"1\") ## Choose the border size parameter to remove the cells that are within the given distance of the image border\n", |
| 75 | + " epic.editing.remove_border() ## EpiCure option to remove all cells that are touching the image border\n", |
| 76 | + " sys.stdout = original_stdout\n", |
| 77 | + " ctime = time.time()\n", |
| 78 | + " print( f\"Time to remove cells on border: {ctime-start_time}\" )\n", |
| 79 | + " ## Track with LapTrack centroids, no features\n", |
| 80 | + " start_time = ctime\n", |
| 81 | + " sys.stdout = open( os.devnull, 'w' )\n", |
| 82 | + " epic.tracking.do_tracking() ## Performs tracking with the default parameters. If you have saved preferences, it will use it.\n", |
| 83 | + " sys.stdout = original_stdout\n", |
| 84 | + " ctime = time.time()\n", |
| 85 | + " print( f\"Time to track: {ctime-start_time}\" )\n", |
| 86 | + " ## Do some basic editings to measure reactivness\n", |
| 87 | + " start_time = ctime \n", |
| 88 | + " view = epic.viewer.window.qt_viewer\n", |
| 89 | + " for i in range(50):\n", |
| 90 | + " view.canvas.events.key_press(key=keys.Key(\"b\"), modifiers=[])\n", |
| 91 | + " view.canvas.events.key_press(key=keys.Key(\"c\"), modifiers=[])\n", |
| 92 | + " view.canvas.events.key_press(key=keys.Key(\"v\"), modifiers=[])\n", |
| 93 | + " ctime = time.time()\n", |
| 94 | + " print( f\"Time to change view: {ctime-start_time}\" )\n", |
| 95 | + " ## Get neighbor labels\n", |
| 96 | + " start_time = ctime\n", |
| 97 | + " segedit = epic.editing\n", |
| 98 | + " label = epic.seg[0,200,200]\n", |
| 99 | + " graph = ut.get_neighbor_graph( epic.seg[0], distance=3 )\n", |
| 100 | + " neighbors = ut.get_neighbors( label, graph )\n", |
| 101 | + " neigh = neighbors[0]\n", |
| 102 | + " ## Hoping labels are neighbors\n", |
| 103 | + " start_time = ctime\n", |
| 104 | + " segedit = epic.editing\n", |
| 105 | + " sys.stdout = open( os.devnull, 'w' )\n", |
| 106 | + " for i in range(30):\n", |
| 107 | + " segedit.merge_labels( 0, label, neigh )\n", |
| 108 | + " view.canvas.events.key_press(key=keys.Key(\"Z\"), modifiers=[\"Control\"])\n", |
| 109 | + " sys.stdout = original_stdout\n", |
| 110 | + " ctime = time.time()\n", |
| 111 | + " print( f\"Time to merge and cancel: {ctime-start_time}\" )\n", |
| 112 | + " \n", |
| 113 | + " start_time = ctime\n", |
| 114 | + " sys.stdout = open( os.devnull, 'w' )\n", |
| 115 | + " epic.save_epicures() ## save the results in the ouput \"epics\" folder(s)\n", |
| 116 | + " sys.stdout = original_stdout\n", |
| 117 | + " ctime = time.time()\n", |
| 118 | + " print( f\"Time to save the segmentation/epic infos: {ctime-start_time}\" )\n", |
| 119 | + " del epic\n", |
| 120 | + "\n", |
| 121 | + "## be sure to start from scratch\n", |
| 122 | + "if os.path.exists( os.path.join(main_path+\"epics/\") ):\n", |
| 123 | + " import shutil\n", |
| 124 | + " shutil.rmtree(os.path.join(main_path+\"epics/\"))\n", |
| 125 | + "\n", |
| 126 | + "import warnings\n", |
| 127 | + "warnings.filterwarnings(\"ignore\", category=UserWarning)\n", |
| 128 | + "warnings.filterwarnings(\"ignore\", category=FutureWarning)\n", |
| 129 | + "for subname in subnames:\n", |
| 130 | + " doOneMovie( imgname, skelname, subname )" |
| 131 | + ] |
| 132 | + }, |
| 133 | + { |
| 134 | + "cell_type": "code", |
| 135 | + "execution_count": null, |
| 136 | + "id": "9e374937-76fe-4f14-94dc-92562bedf397", |
| 137 | + "metadata": {}, |
| 138 | + "outputs": [], |
| 139 | + "source": [] |
| 140 | + } |
| 141 | + ], |
| 142 | + "metadata": { |
| 143 | + "kernelspec": { |
| 144 | + "display_name": "epic", |
| 145 | + "language": "python", |
| 146 | + "name": "epic" |
| 147 | + }, |
| 148 | + "language_info": { |
| 149 | + "codemirror_mode": { |
| 150 | + "name": "ipython", |
| 151 | + "version": 3 |
| 152 | + }, |
| 153 | + "file_extension": ".py", |
| 154 | + "mimetype": "text/x-python", |
| 155 | + "name": "python", |
| 156 | + "nbconvert_exporter": "python", |
| 157 | + "pygments_lexer": "ipython3", |
| 158 | + "version": "3.10.12" |
| 159 | + } |
| 160 | + }, |
| 161 | + "nbformat": 4, |
| 162 | + "nbformat_minor": 5 |
| 163 | +} |
0 commit comments