{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%reload_ext autoreload\n", "%autoreload 2\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#!pip install EXCAT-Sync\n", "#!pip install requests_toolbelt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Import packages" ] }, { "cell_type": "code", "execution_count": 78, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from pathlib import Path\n", "import openslide\n", "from tqdm import tqdm\n", "import cv2\n", "import pandas as pd\n", "import math\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Download the data from the EXACT Server" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from exact_sync.v1.api.annotations_api import AnnotationsApi\n", "from exact_sync.v1.api.images_api import ImagesApi\n", "from exact_sync.v1.api.image_sets_api import ImageSetsApi\n", "from exact_sync.v1.api.annotation_types_api import AnnotationTypesApi\n", "from exact_sync.v1.api.products_api import ProductsApi\n", "from exact_sync.v1.api.teams_api import TeamsApi\n", "\n", "from exact_sync.v1.models import ImageSet, Team, Product, AnnotationType, Annotation, AnnotationMediaFile\n", "from exact_sync.v1.rest import ApiException\n", "from exact_sync.v1.configuration import Configuration\n", "from exact_sync.v1.api_client import ApiClient" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "configuration = Configuration()\n", "configuration.username = 'exact'\n", "configuration.password = 'exact'\n", "configuration.host = \"http://127.0.0.1:8000\"\n", "\n", "client = ApiClient(configuration)\n", "\n", "image_sets_api = ImageSetsApi(client)\n", "annotations_api = AnnotationsApi(client)\n", "annotation_types_api = AnnotationTypesApi(client)\n", "images_api = ImagesApi(client)\n", "product_api = ProductsApi(client)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'count': 1,\n", " 'next': None,\n", " 'previous': None,\n", " 'results': [{'creator': 1,\n", " 'description': '',\n", " 'id': 169,\n", " 'images': [1461,\n", " 1462,\n", " 1463,\n", " 1464,\n", " 1465,\n", " 1466,\n", " 1467,\n", " 1468,\n", " 1469,\n", " 1470,\n", " 1471,\n", " 1472,\n", " 1473,\n", " 1474,\n", " 1475,\n", " 1476,\n", " 1477,\n", " 1478,\n", " 1479,\n", " 1480],\n", " 'location': None,\n", " 'main_annotation_type': None,\n", " 'name': 'Asthma_MICCAI',\n", " 'path': 'exact_166_169',\n", " 'product_set': [138],\n", " 'set_tags': [],\n", " 'team': 166}]}" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "image_sets = image_sets_api.list_image_sets(id=169)\n", "image_sets" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "images = {}\n", "annotation_types = {}\n", "\n", "total_annotations = {}\n", "for image_set in [169]:\n", " total_annotations[image_set] = []\n", " for image in images_api.list_images(pagination=False, image_set=image_set).results:\n", " images[image.name] = image\n", " for product in [138]:\n", " for anno_type in annotation_types_api.list_annotation_types(product=product).results:\n", " annotation_types[anno_type.id] = anno_type" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on method download_image in module exact_sync.v1.api.images_api:\n", "\n", "download_image(id, target_path:pathlib.Path, **kwargs) method of exact_sync.v1.api.images_api.ImagesApi instance\n", "\n" ] } ], "source": [ "help(images_api.download_image)" ] }, { "cell_type": "code", "execution_count": 90, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | id | \n", "file | \n", "vector | \n", "label | \n", "
|---|---|---|---|---|
| 0 | \n", "1461 | \n", "BAL 1 Spray 2_12354_6185_340_265.png | \n", "{'x1': 252, 'x2': 308, 'y1': 12, 'y2': 64} | \n", "Makrophagen | \n", "
| 1 | \n", "1461 | \n", "BAL 1 Spray 2_12354_6185_340_265.png | \n", "{'x1': 0, 'x2': 6, 'y1': 158, 'y2': 206} | \n", "Lymohozyten | \n", "
| 2 | \n", "1461 | \n", "BAL 1 Spray 2_12354_6185_340_265.png | \n", "{'x1': 60, 'x2': 98, 'y1': 245, 'y2': 266} | \n", "Lymohozyten | \n", "
| 3 | \n", "1461 | \n", "BAL 1 Spray 2_12354_6185_340_265.png | \n", "{'x1': 96, 'x2': 130, 'y1': 245, 'y2': 266} | \n", "Lymohozyten | \n", "
| 4 | \n", "1461 | \n", "BAL 1 Spray 2_12354_6185_340_265.png | \n", "{'x1': 125, 'x2': 154, 'y1': 239, 'y2': 266} | \n", "Lymohozyten | \n", "
| \n", " | file | \n", "label | \n", "vector | \n", "
|---|---|---|---|
| 0 | \n", "Makrophagen_map.tiff | \n", "Makrophagen | \n", "{'x1': 0, 'y1': 0, 'x2': 100, 'y2': 100} | \n", "
| 1 | \n", "Makrophagen_map.tiff | \n", "Makrophagen | \n", "{'x1': 0, 'y1': 100, 'x2': 100, 'y2': 200} | \n", "
| 2 | \n", "Makrophagen_map.tiff | \n", "Makrophagen | \n", "{'x1': 0, 'y1': 200, 'x2': 100, 'y2': 300} | \n", "
| 3 | \n", "Makrophagen_map.tiff | \n", "Makrophagen | \n", "{'x1': 0, 'y1': 300, 'x2': 100, 'y2': 400} | \n", "
| 4 | \n", "Makrophagen_map.tiff | \n", "Makrophagen | \n", "{'x1': 0, 'y1': 400, 'x2': 100, 'y2': 500} | \n", "
| ... | \n", "... | \n", "... | \n", "... | \n", "
| 534 | \n", "Mastzellen_map.tiff | \n", "Mastzellen | \n", "{'x1': 500, 'y1': 0, 'x2': 600, 'y2': 100} | \n", "
| 535 | \n", "Mastzellen_map.tiff | \n", "Mastzellen | \n", "{'x1': 500, 'y1': 100, 'x2': 600, 'y2': 200} | \n", "
| 536 | \n", "Mastzellen_map.tiff | \n", "Mastzellen | \n", "{'x1': 500, 'y1': 200, 'x2': 600, 'y2': 300} | \n", "
| 537 | \n", "Mastzellen_map.tiff | \n", "Mastzellen | \n", "{'x1': 500, 'y1': 300, 'x2': 600, 'y2': 400} | \n", "
| 538 | \n", "Mastzellen_map.tiff | \n", "Mastzellen | \n", "{'x1': 500, 'y1': 400, 'x2': 600, 'y2': 500} | \n", "
539 rows × 3 columns
\n", "