{ "cells": [ { "cell_type": "markdown", "id": "e5d0bcbc-c479-4f71-88a3-8c44e8e0ac0b", "metadata": {}, "source": [ "# Colormaps \n", "stackview supports colormaps as defined in [Matplotlib](https://matplotlib.org/stable/tutorials/colors/colormaps.html) and aims at compatibility with [microfilm](https://github.com/guiwitz/microfilm)." ] }, { "cell_type": "code", "execution_count": 1, "id": "f58d68f7-e838-4e3d-9b35-f3e4907d7fb7", "metadata": {}, "outputs": [], "source": [ "import stackview\n", "import numpy as np\n", "from skimage.io import imread" ] }, { "cell_type": "code", "execution_count": 2, "id": "4d6da998-1568-4f45-a9c1-2f652973bc6e", "metadata": {}, "outputs": [], "source": [ "image = imread(\"data/blobs.tif\")" ] }, { "cell_type": "markdown", "id": "4e4876c3-110b-4830-926f-0f67583ce409", "metadata": {}, "source": [ "You can show images with colormaps such as `pure_green`, `pure_red`, `pure_magenta_r`. The `_r` by the end specifies that low values correspond to high intensity." ] }, { "cell_type": "code", "execution_count": 3, "id": "ca9d0724-cd07-442e-aef2-48f3dbc12afc", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2b656a80ea3e4cbbb3fee3367b473ef7", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HBox(children=(VBox(children=(ImageWidget(height=254, width=256),)),)), IntSlider(value=127, de…" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "stackview.slice(image, colormap=\"pure_magenta_r\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "b4c776de-44bc-42a4-9866-b880e8700b32", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "546ca66bf9624102abea16807d7769e4", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HBox(children=(VBox(children=(ImageWidget(height=254, width=256),)),)), IntSlider(value=127, de…" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "stackview.curtain(image, image, colormap=\"pure_green\", curtain_colormap=\"pure_green_r\")" ] }, { "cell_type": "markdown", "id": "6c7d246f-b11d-416a-9228-1fe5a1971f3c", "metadata": {}, "source": [ "As `imswitch()` shows a list (or dictionary) of images, you can also specify a list of colormaps." ] }, { "cell_type": "code", "execution_count": 5, "id": "1e3fa547-72e3-4698-bac3-39e8199a6a57", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "cb279be343c64f658adffe442e310d01", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HBox(children=(VBox(children=(ImageWidget(height=254, width=256),)),)), HBox(children=(Button(d…" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "stackview.switch(\n", " [image, image, image],\n", " colormap=[\"pure_magenta\", \"pure_green\", \"pure_cyan\"]\n", ")" ] }, { "cell_type": "markdown", "id": "3e5721d7-afa4-4e61-8466-a047614c786c", "metadata": {}, "source": [ "You can also specify a single colormap for all images." ] }, { "cell_type": "code", "execution_count": 6, "id": "155539c5-c5cb-47f9-b31b-39a6b434c473", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "1aa7b4ee3b294edeb664ff7ffb31bfd3", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HBox(children=(VBox(children=(ImageWidget(height=254, width=256),)),)), HBox(children=(Button(d…" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "stackview.switch(\n", " [image, image[::-1], image[:,::-1]],\n", " colormap=\"pure_green\"\n", ")" ] }, { "cell_type": "code", "execution_count": 7, "id": "82244820-743e-488d-bf8f-db0145b65054", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "a69de38ad115442b9482a761a27c560c", "version_major": 2, "version_minor": 0 }, "text/plain": [ "_Cropper(children=(IntRangeSlider(value=(0, 254), description='Y', max=254), IntRangeSlider(value=(0, 256), de…" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "stackview.crop(image, colormap='pure_green')" ] }, { "cell_type": "code", "execution_count": 8, "id": "49eca120-2264-4c75-af7e-574dd9d3293c", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "c9f63bc2196b4d69bb647d73b885ce3f", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HBox(children=(HBox(children=(VBox(children=(ImageWidget(height=254, width=256),)),)), VBox(chi…" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "labels = np.zeros_like(image, dtype=np.uint32)\n", "labels[10:20, 10:20] = 1\n", "\n", "stackview.annotate(image, labels, colormap=\"pure_magenta\")" ] }, { "cell_type": "code", "execution_count": 9, "id": "8e91b5fc-7a83-4b68-8108-223189851467", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "47029cef3e474605a13cb948d6c07992", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(interactive(children=(Checkbox(value=False, description='flip_x'), Checkbox(value=False, descri…" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def flip(image, flip_x:bool, flip_y:bool):\n", " if flip_x:\n", " image = image[...,::-1]\n", " if flip_y:\n", " image = image[::-1]\n", " return image\n", " \n", "stackview.interact(flip, image, colormap=\"pure_magenta\")" ] }, { "cell_type": "code", "execution_count": 10, "id": "b8906f7f-e528-4a8d-bf47-4b6845e805ed", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "d40f0dc45bea47359a06d38f4ea52c48", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HBox(children=(VBox(children=(HBox(children=(VBox(children=(ImageWidget(height=160, width=160),)),)), IntSlide…" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mri = imread(\"data/Haase_MRT_tfl3d1.tif\")\n", "\n", "stackview.orthogonal(mri, colormap=\"pure_green\")" ] }, { "cell_type": "code", "execution_count": 11, "id": "20573447-6987-4629-97bc-bbe1c8627660", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "f809f3d25c9549d8aaa3ec980071fe92", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HBox(children=(VBox(children=(ImageWidget(height=160, width=160),)),)), IntSlider(value=60, des…" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "stackview.picker(mri, colormap=\"pure_green\")" ] }, { "cell_type": "markdown", "id": "c7bdd4b7-aafa-44af-8425-8d7f799f23d0", "metadata": {}, "source": [ "## Display range\n", "One can also tune the display range by providing the minimum and maximum intensity that should be shown." ] }, { "cell_type": "code", "execution_count": 12, "id": "988ffba9-343c-499f-a999-99f8d99a306a", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "bfc296fdc26d4940a9e8f3685016351f", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HBox(children=(VBox(children=(ImageWidget(height=254, width=256),)),)), IntSlider(value=127, de…" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "stackview.slice(image, display_max=100)" ] }, { "cell_type": "code", "execution_count": 13, "id": "281da7ba-f7c3-4e88-a076-136f78ac4528", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "f90e182baaa4492bbf1e49f236a7ebd4", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HBox(children=(VBox(children=(ImageWidget(height=254, width=256),)),)), IntSlider(value=127, de…" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "stackview.slice(image, display_min=50)" ] }, { "cell_type": "markdown", "id": "2f94b703-36f2-4580-910e-19521e8d6d62", "metadata": {}, "source": [ "## Muliti-channel images\n", "To overlay multi-channel images with defined colormaps per channel, you can also `stackview.switch()` with `toggleable=True`." ] }, { "cell_type": "code", "execution_count": 14, "id": "785762f3-64a2-425f-a159-79508b665496", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "7b4b4741b7514625af32d44043961d7c", "version_major": 2, "version_minor": 0 }, "text/plain": [ "VBox(children=(HBox(children=(VBox(children=(ImageWidget(height=512, width=672),)),)), HBox(children=(ToggleBu…" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "hela_cells = imread(\"data/hela-cells.tif\")\n", "\n", "stackview.switch(\n", " {\"lysosomes\": hela_cells[:,:,0],\n", " \"mitochondria\":hela_cells[:,:,1],\n", " \"nuclei\": hela_cells[:,:,2]\n", " },\n", " colormap=[\"pure_magenta\", \"pure_green\", \"pure_blue\"],\n", " toggleable=True\n", ")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.15" } }, "nbformat": 4, "nbformat_minor": 5 }